-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Handle types.ModuleType #3107
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
Handle types.ModuleType #3107
Conversation
mypy/semanal.py
Outdated
all objects found in the stub. This is to provide correct output from | ||
reveal_type for definitions placed in the "wrong" module for circular | ||
import reasons (e.g., the definition of ModuleType in | ||
_importlib_modulespec.pyi instead of type.pyi). |
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.
types.pyi
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.
just in time for the last commit =)
And the next commit is just to remove seemingly superfluous |
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.
I also found that , in addition to removing module
from builtins.pyi
, we also need to add (at least) __dict__
to the ModuleType
class in types.pyi
. (And all this for PY2 and PY3.)
test-data/unit/lib-stub/types.pyi
Outdated
|
||
class bool: ... | ||
|
||
class ModuleSpec: |
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.
Is it possible to prune the contents of this file some? It looks like you just copied from typeshed -- but in order to avoid slowing down the tests we should really only include attributes that tests reference.
There are also other changes needed to typeshed; various stubs apparently reference |
This depends on python/mypy#3107.
reveal_type(f()) # E: Revealed type is 'types.ModuleType' | ||
reveal_type(types) # E: Revealed type is 'types.ModuleType' | ||
|
||
[builtins fixtures/module.pyi] |
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.
Please add a \n character at the end of this line.
I don't understand what happend to the tests, perhaps because you included a typeshed sync? I think you may have to undo that part. |
@gvanrossum Ah, I didn't know I have to Edit: nope, I'm looking into it. |
I debugged the test failure a little bit and found that this probably is needed, but not sufficient:
FWIW to debug this I modified errors.py to always enter pdb (changed line 542 into
Hope this helps, I probably won't have time for more assistance. |
Also, you cannot include the typeshed merge in this PR. You should only use commits on typeshed's master branch. AFAIK the typeshed PR is not required for this PR to pass (though it is required for some Dropbox internals to pass, but that's not important). The order in which we commit things should be:
|
Tests: thanks, your analysis helped. Also, They fail (apart from
We should try to merge this as soon as possible, to save people from having code that breaks when |
@pkch Since fine grained incremental is still WIP, I think it is fine to merge this now. I am going to merge this when tests pass |
This depends on python/mypy#3107.
Changes of doing the same for builtins.function? |
Specifically to include python/typeshed#1156 which is important follow-up for #3107.
Looking at |
@ilevkivskyi Sure, but it seems that with this change, every test needs Do we want to do some workaround, like manually inject |
You could just try adding |
Fixes #1498
The only issue is that
reveal_type
reports'_importlib_modulespec.ModuleType'
instead of'typing.ModuleType'
for module objects. I fix that in the next commit (I want to separate this PR into 2 commits, since my second commit adds a new feature to the parser, which I'm not sure is appropriate; this way it would be easy to just discard the 2nd commit).Also, if this is merged, we can delete
class module
frombuiltins.pyi
(it's not needed any more).