-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Make sys.modules a Dict[str, Any] #1266
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
Conversation
Modules can contain anything, so give them a generic "__getattr__(name) -> Any".
This makes code like the following type-check, in pytype:
sys.modules.get("random").randint
|
Sounds reasonable, but this appears to break some of mypy's tests. |
|
Yep. I'll undo the Python 3 change for now. |
|
Hold on, the test failure suggests that there's something fundamental wrong here. With this change mypy believes that every module has every attribute. E.g. |
|
Maybe declaring sys.modules to be of type |
|
Fine with me. As a matter of fact, that's how it was already defined in |
Dict[str, Any]
Dict[str, Any]
gvanrossum
left a 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.
Much better!
|
[Hey @JelleZijlstra, nexttime, in addition to editing the commit subject line, could you also trim the local commits from the final commit message? In this case they are particularly unhelpful, since they were all undone.] |
|
Makes sense, will remember that for next time. |
* Add __getattr__ to ModuleType.
Modules can contain anything, so give them a generic "__getattr__(name) -> Any".
This makes code like the following type-check, in pytype:
sys.modules.get("random").randint
* undo Python 3 change
* Revert "undo Python 3 change"
This reverts commit 96cf2d5.
* Revert "Add __getattr__ to ModuleType."
This reverts commit 3ac1cf8.
* In stdlib/2/, make sys.modules a Dict[str, Any].
(Instead of Dict[str, ModuleType])
Same as stdlib/3/.
Modules can contain anything, so give them a generic
__getattr__(name) -> Any.This makes code like the following type-check, in pytype: