-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
False positive when calling object.__new__ inside __new__ with args #4190
Labels
Comments
I think #1021 is closely related. |
ilevkivskyi
added
bug
mypy got something wrong
priority-0-high
false-positive
mypy gave an error on correct code
labels
May 18, 2018
Interestingly, the following works:
|
I think the fix for this is to make the type of |
msullivan
added a commit
that referenced
this issue
Sep 19, 2018
Currently the first argument to `__new__` and classmethods is a callable type that is constructed during semantic analysis by typechecker code (!) that looks for the `__init__`/`__new__` methods. This causes a number of problems, including not being able to call `object.__new__` in a subclass's `__new__` if it took arguments (#4190) and giving the wrong type if `__init__` appeared after the class method (#1727). Taking a `Type` instead lets us solve those problems, and postpone computing the callable version of the type until typechecking if it is needed. This also lets us drop a bunch of plugin code that tries to fix up the types of its cls arguments post-hoc, sometimes incorrectly (#5263). Fixes #1727. Fixes #4190. Fixes #5263.
(By which you mean, mypy should set it to that, right?) |
msullivan
added a commit
that referenced
this issue
Sep 21, 2018
Currently the first argument to `__new__` and classmethods is a callable type that is constructed during semantic analysis by typechecker code (!) that looks for the `__init__`/`__new__` methods. This causes a number of problems, including not being able to call `object.__new__` in a subclass's `__new__` if it took arguments (#4190) and giving the wrong type if `__init__` appeared after the class method (#1727). Taking a `Type` instead lets us solve those problems, and postpone computing the callable version of the type until typechecking if it is needed. This also lets us drop a bunch of plugin code that tries to fix up the types of its cls arguments post-hoc, sometimes incorrectly (#5263). Fixes #1727. Fixes #4190. Fixes #5263.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Consider:
The
object.__new__(cls)
call type checks when inside a__new__
method with a single argument, but not when there are extra arguments.The code for
A
is taken fromtestSuperWithNew
, but becauseobject.__new__
is unannotated infixtures/__new__.pyi
, the type error doesn't show up in the unit test. The discrepancy between the fixture and typeshed was noted in #3111.The text was updated successfully, but these errors were encountered: