Skip to content

Fix some types to peewee - #12788

Merged
srittau merged 5 commits into
python:mainfrom
s-yh-china:fix/peewee-node-copy
Oct 13, 2024
Merged

srittau merged 5 commits into
python:mainfrom
s-yh-china:fix/peewee-node-copy

Conversation

@s-yh-china

Copy link
Copy Markdown
Contributor

Among the methods that originally returned None type, there are some of methods annotated by @Node.copy
according to the code review, it can be inferred that these methods actually return type Self

    @staticmethod
    def copy(method):
        def inner(self, *args, **kwargs):
            clone = self.clone()
            method(clone, *args, **kwargs)
            return clone
        return inner

so I fixed these incorrect return type

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@srittau

srittau commented Oct 13, 2024

Copy link
Copy Markdown
Collaborator

I don't have experience with peewee, but the changes seem correct to me. But mypy seems to have a problem with the same method returning Self in two different base classes:

from typing import Self

class Base1:
    def foo(self) -> Self:
        return self
    
class Base2:
    def foo(self) -> Self:
        return self
    
class Sub(Base1, Base2):  # error: Definition of "foo" in base class "Base1" is incompatible with definition in base class "Base2"  [misc]
    pass

(python/mypy#14640)

I'm not sure why that is, but for the moment the best solution is to mark those lines with # type: ignore[misc].

@s-yh-china

s-yh-china commented Oct 13, 2024 •

Copy link
Copy Markdown
Contributor Author

thank you for your reminder. i will first add # type: ignore [misc] to pass the check

@github-actions

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@srittau
srittau merged commit 86e144b into python:main Oct 13, 2024
@s-yh-china
s-yh-china deleted the fix/peewee-node-copy branch October 13, 2024 13:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants