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

Prefer __new__ over __init__ for determining callable type of a class #5647

Open
msullivan opened this issue Sep 19, 2018 · 1 comment · May be fixed by #18093
Open

Prefer __new__ over __init__ for determining callable type of a class #5647

msullivan opened this issue Sep 19, 2018 · 1 comment · May be fixed by #18093

Comments

@msullivan
Copy link
Collaborator

#5642 made __new__ chosen in more situations but __init__ is still chosen when
one class defines both. The difficulty is that typeshed has a bunch of dodgy __new__
annotations that need to be cleaned up first.

@hauntsaninja
Copy link
Collaborator

Here's an example (simplified from a post in the gitter today) where we get a terrible error message because IntEnum subclasses int.

~/delete λ cat test34.py
from enum import IntEnum

IntEnum("Fruit", "Apple Pear")
~/delete λ mypy test34.py
test34.py:3: error: No overload variant of "IntEnum" matches argument types "str", "str"
test34.py:3: note: Possible overload variant:
test34.py:3: note:     def IntEnum(self, x: Union[str, bytes, bytearray], base: int) -> IntEnum
test34.py:3: note:     <1 more non-matching overload not shown>
Found 1 error in 1 file (checked 1 source file)

Curious if you remember what the problematic typeshed __new__s are?

hauntsaninja added a commit to hauntsaninja/mypy that referenced this issue Nov 3, 2024
@hauntsaninja hauntsaninja linked a pull request Nov 3, 2024 that will close this issue
hauntsaninja added a commit to hauntsaninja/mypy that referenced this issue Nov 3, 2024
hauntsaninja added a commit to hauntsaninja/mypy that referenced this issue Nov 3, 2024
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 a pull request may close this issue.

2 participants