-
-
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
Allow function arguments as base classes #14135
Conversation
This comment has been minimized.
This comment has been minimized.
The
reveals type |
OK, I have a fix for the walrus bug, since it is an obvious bug, I am going to just add it to this PR. |
This comment has been minimized.
This comment has been minimized.
Looking again at |
Diff from mypy_primer, showing the effect of this PR on open source code: artigraph (https://github.com/artigraph/artigraph)
+ tests/arti/producers/test_producer.py:679: error: Unused "type: ignore" comment
+ tests/arti/producers/test_producer.py:680: error: Unused "type: ignore" comment
Tanjun (https://github.com/FasterSpeeding/Tanjun)
- tanjun/dependencies/reloaders.py:566: error: Cannot determine type of "real_path" [has-type]
- tanjun/dependencies/reloaders.py:567: error: Cannot determine type of "time" [has-type]
- tanjun/dependencies/reloaders.py:578: error: Cannot determine type of "info" [has-type]
- tanjun/dependencies/reloaders.py:579: error: Cannot determine type of "time" [has-type]
- tanjun/dependencies/reloaders.py:599: error: Cannot determine type of "path" [has-type]
- tanjun/dependencies/reloaders.py:600: error: Cannot determine type of "tracked_value" [has-type]
- tanjun/dependencies/reloaders.py:609: error: Cannot determine type of "path" [has-type]
- tanjun/dependencies/reloaders.py:609: error: Cannot determine type of "path_info" [has-type]
- tanjun/commands/menu.py:580: error: Incompatible return value type (got "MenuCommand[_MenuCommandCallbackSigT, _MenuTypeT]", expected "Self") [return-value]
mypy (https://github.com/python/mypy)
+ mypy/stubtest.py:357: error: Unused "type: ignore[valid-type]" comment
cloud-init (https://github.com/canonical/cloud-init)
+ cloudinit/templater.py:44: error: Unused "type: ignore" comment
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice -- fixing three bugs for the price of one!
I can't see why setting the argument types in the semantic analyzer would be a problem.
Left a comment that is mostly unrelated to this PR, feel free to ignore it if you are not sure.
Fixes #5865
Looks quite easy and safe, unless I am missing something. Most changes in the diff are just moving stuff around.
Previously we only applied argument types before type checking, but it looks like we can totally do this in semantic analyzer. I also enable variable annotated as
type
(or equivalentlyType[Any]
), this use case was mentioned in the comments.This PR also accidentally fixes two additional bugs, one related to type variables with values vs walrus operator, another one for type variables with values vs self types. I include test cases for those as well.