Skip to content
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

Regression in 0.740 for __init__subclass__ #7735

Closed
tdamsma opened this issue Oct 17, 2019 · 2 comments · Fixed by #7739
Closed

Regression in 0.740 for __init__subclass__ #7735

tdamsma opened this issue Oct 17, 2019 · 2 comments · Fixed by #7739
Assignees
Labels
bug mypy got something wrong false-positive mypy gave an error on correct code priority-0-high

Comments

@tdamsma
Copy link

tdamsma commented Oct 17, 2019

The following code does not throw errors in 0.730, but does in 0.740. Likely to do with #7723

class A:
    def __init_subclass__(cls, *args, **kwargs):
        super().__init_subclass__(*args, **kwargs)


class B(A):
    pass

# error: Too few arguments for "__init_subclass__"

And slightly more complicated, a self registering subclass:

from typing import ClassVar, List, Type


class A:
    registered_classes: ClassVar[List[Type["A"]]] = []

    def __init_subclass__(cls, *args, register=True, **kwargs):
        if register:
            cls.registered_classes.append(cls)
        super().__init_subclass__(*args, **kwargs)


class B(A):
    pass


class C(A, register=False):
    pass


class D(C):
    pass


print(A.registered_classes) # >>> [<class '__main__.B'>, <class '__main__.D'>]

# 13: error: Too few arguments for "__init_subclass__"
# 17: error: Missing positional argument "cls" in call to "__init_subclass__"
# 21: error: Too few arguments for "__init_subclass__"
@ilevkivskyi
Copy link
Member

Thanks for reporting! This is quite subtle issue, #7739 should fix this.

@ilevkivskyi ilevkivskyi added bug mypy got something wrong false-positive mypy gave an error on correct code priority-0-high labels Oct 17, 2019
@ilevkivskyi ilevkivskyi self-assigned this Oct 17, 2019
ttung pushed a commit to spacetx/starfish that referenced this issue Oct 17, 2019
[This](python/mypy#7735) causes spurious errors.
ttung pushed a commit to spacetx/starfish that referenced this issue Oct 17, 2019
[This](python/mypy#7735) causes spurious errors.
ilevkivskyi added a commit that referenced this issue Oct 20, 2019
Fixes #7735

The fix is quite straightforward, this was not triggered before because all common cases go troigh other code paths.
@tdamsma
Copy link
Author

tdamsma commented Oct 20, 2019

@ilevkivskyi Thanks for the quick fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong false-positive mypy gave an error on correct code priority-0-high
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants