-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Wrong inference of the target of __new__
#9405
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
Comments
__new__
__new__
I think this could actually be fixed in typeshed -- the problem seems to be that no But another interpretation would be that we ought to automatically derive a signature for |
I’m not good at Python insides, anyway, my understanding is that the two issues are not that much related. The other issue as I understand it, is about I did not knew about typeshed, so just had a look: https://github.com/python/typeshed/blob/master/stdlib/2and3/builtins.pyi#L443 Indeed, no |
That said, I wonder if the error is finally in typeshed: I believe that’s a |
Would you mind filing a bug with typeshed then? I wonder though if there's
more to it. If we switch these to `__new__`, will anything break?
|
We tried this before in python/typeshed#1352 and terrible things happened (see python/typeshed#1464). Perhaps the enum issue I found back then got solved some other way since then, though. |
Cannot be reproduced on mypy 0.800+ |
🐛 Bug Report
The target of an invocation of
__new__
is an explicit class, butmypy
erroneously believes it is another class.To Reproduce
Create a file
test.py
with this content:Then run
mypy test.py
Side note # 1: this is a stripped down version to reproduce the issue, the original case has more real interest.
Side note # 2:
__new__
should returnC
but the nameC
is not defined during class creation, so__new__
is declared to returnAny
, instead.Expected Behavior
There should be no error, as one can check this way:
Actual Behavior
mypy
complains:It erroneously believes the target of
__new__
isobject
while it isstr
Your Environment
mypy.ini
(and other config files): none (no config file)The text was updated successfully, but these errors were encountered: