-
-
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
Attribute access with untyped methods and --check-untyped-defs #5401
Comments
Yes, mypy doesn't type-check unannotated methods, but it still processes reveal_type() there. |
@gvanrossum Please note that I called mypy with |
Oh, sorry. |
This isn't just for descriptors; it happens for plain attributes too:
|
So should the subject just be "reveal_type() in untyped methods with --check-untyped-defs incorrectly shows Any"? |
It's not just
|
Yes, I also only used |
So is —check-I typed-refs totally broken then? Maybe that should be the
topic.
|
It'll report some errors, so not totally broken. It looks like the difference is in the handling of |
The |
Since this behavior is enabled explicitly by a flag ( |
I have analyzed this problem a bit and solution seems non-straightforward. Currently for annotated methods the argument type of Lines 488 to 501 in e5e4532
It's possible to add a type to unannotated methods here as well, but that wreaks havoc with later checks for unannotated or partially annotated methods when using The checker later constructs a type for functions and methods that don't have one yet: Lines 755 to 765 in e5e4532
As far as I can see the class type is not available in this method, so it needs to be injected somehow. But I don't like the fact that the self type gets injected in two completely separate locations, depending on whether the method is annotated at all or not. I see three possible solutions:
|
For code bases with lots of classes (e.g. Django code bases) this is really misleading. You pass If you annotate any of a function's args or its return type, IMO as is |
@kylebebak It took me a few tries to understand what you're proposing, but basically you're saying that with Alas, I am not very familiar with this part of mypy, and I have no idea how easy it would be to implement any of @srittau's proposals. I'm setting the priority to "normal", hopefully @JukkaL or @ilevkivskyi will be able to help. |
Sorry if that wasn't as clear as it could have been... And yes, that's exactly what I'm proposing. Hopefully it's not too difficult to change this behavior! |
See @srittau’s explanation above.
--
--Guido (mobile)
|
According to @srittau , it would be simple to modify If this is the only drawback to this solution, and other solutions that allow We just add a warning to The reasoning being that the purpose of one runs sort of contrary, or at least perpendicular, to the purpose of the other. I don't think it's very important that they work together, and as we've all sort of agreed, currently |
) This is accomplished by updating the helper that constructs a callable type from a func def to fill in the self argument. Also suppress errors about `need type annotation` in most cases in a checked but untyped method. This will make check_untyped_defs a lot more useful. Closes #7309, #5401, #4637, #1514
Using mypy 0.620 and Python 3.7.0 I see strange behavior with descriptors in untyped methods. For example:
Running with
mypy --check-untyped-defs
I get the following output:Is this intended?
The text was updated successfully, but these errors were encountered: