You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
stubtest reports imported name as not present at runtime even though it's not reexported #8649
Are you reporting a bug, or opening a feature request?
A bug, unless this is somehow intended behavior.
Please insert below the code you are checking with mypy,
or a mock-up repro if the source is private. We would appreciate
if you try to simplify your case to a minimal repro.
error: stubtest_bug.foo.Bar is not present at runtime
Stub: at line -1
Any
Runtime:
MISSING
error: stubtest_bug.foo.Baz is not present at runtime
Stub: at line -1
Any
Runtime:
MISSING
What is the behavior/output you expect?
Given that Baz is reexported while Bar isn't, I would only expect an error for Baz. Importing a name that's not present at runtime in the stub to use in type annotations is a common use case and shouldn't produce errors, since Mypy won't let you import that name anyway without it being reexported.
Note that this seems to work as expected if there are annotations for the module you import from. The error only occurs if you import from a module without annotations and stick a type ignore comment at the import (the latter is needed to make stubtest run at all).
What are the versions of mypy and Python you are using?
Do you see the same issue after installing mypy from Git master?
Python 3.7.3 and Mypy 0.770. I haven't tested master, but seems like there haven't been any changes to stubtest since 0.770 anyway.
stubtest relies on the mypy build process for this kind of information, specifically, the population of the module_public attribute. It seems like in the case where mypy considers the imported module missing (which is the case here, as your type: ignore evidences), it fails to set the module_public attribute correctly, in add_unknown_imported_symbol. I'll attempt a PR soon.
Activity
JelleZijlstra commentedon Apr 8, 2020
cc @hauntsaninja
hauntsaninja commentedon Apr 8, 2020
Thanks for the report and clear repro!
stubtest relies on the mypy build process for this kind of information, specifically, the population of the
module_publicattribute. It seems like in the case where mypy considers the imported module missing (which is the case here, as your type: ignore evidences), it fails to set themodule_publicattribute correctly, inadd_unknown_imported_symbol. I'll attempt a PR soon.semanal: populate module_public even for missing modules
semanal: populate module_public even for missing modules (#8661)