-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
A 'type only' module import should not count as importing a module #11503
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
Comments
like, in a stub there is no way so specify if a module is actually imported at runtime, or if you are just trying to access a type for type time. |
The In a stub, there is a way to specify that the symbol is exported at runtime. PEP 484 documents a mechanism for this. You do so by using a redundant alias form of import, such as |
@erictraut I understand those limitations and agree, it was more just to explain the issue. (although an You haven't got the issue with stubs quite right though. The issue isn't that The issue is that mypy thinks There is no way to specify in a stub that your import is reflected or not at runtime. |
given:
entry.py:
mod.py:
In typeshed/bundled stubs: mod.pyi
OR, if this is fake imported in the .py module: mod.py
package.things.py
When
mypy --strict entry.py
is executed, no error is generated.When
python entry.py
is run:AttributeError: module 'package' has no attribute 'things'
Mypy treats the 'type import' as importing
package.things
, when in reality it isn't. I understand this is consistent with whatTYPE_CHECKING
should do, but seems really sus if you ask me.This more seriously affects typeshed, where all imports are fake and mypy will think all fakely imported modules are really imported.
The text was updated successfully, but these errors were encountered: