Skip to content

Fix some types to peewee #12788

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 13, 2024
Merged

Fix some types to peewee #12788

merged 5 commits into from
Oct 13, 2024

Conversation

s-yh-china
Copy link
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

This comment has been minimized.

This comment has been minimized.

@srittau
Copy link
Collaborator

srittau commented Oct 13, 2024

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
Copy link
Contributor Author

s-yh-china commented Oct 13, 2024

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

Copy link
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
48 checks passed
@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