Skip to content
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

no-implicit-reexport resolves implicit re-exports as Any #12749

Closed
DetachHead opened this issue May 8, 2022 · 4 comments · Fixed by #13967
Closed

no-implicit-reexport resolves implicit re-exports as Any #12749

DetachHead opened this issue May 8, 2022 · 4 comments · Fixed by #13967
Labels
bug mypy got something wrong

Comments

@DetachHead
Copy link
Contributor

DetachHead commented May 8, 2022

# foo.py
class Foo:
    ...
# bar.py
from foo import Foo
# baz.py
from bar import Foo # Module "bar" does not explicitly export attribute "Foo"; implicit reexport disabled  [attr-defined]

reveal_type(Foo) # Revealed type is "Any"

mypy should still resolve the import like it does when no-implicit-reexport is disabled.

in my case, i'm trying to use a library that imports its own classes using implicit re-exports, which results in pretty much everything being treated as Any in my project

#12749 (comment)

@DetachHead DetachHead added the bug mypy got something wrong label May 8, 2022
@KotlinIsland
Copy link
Contributor

KotlinIsland commented May 8, 2022

As a workaround you could apply an override to the mypy config:

[[tool.mypy.overrides]]
module = "thepackage.*"
implicit_reexport = true

@Zeckie
Copy link

Zeckie commented May 21, 2022

Just to be clear - are you expecting mypy to give the error (... does not explicitly export attribute ...) but then still treat it as being exported?

Also, in your examples the files are all .py files - are there stubs for the external libraries? If so, can you change the stubs to have explicit re-exports?

@DetachHead
Copy link
Contributor Author

Just to be clear - are you expecting mypy to give the error (... does not explicitly export attribute ...) but then still treat it as being exported?

yes

Also, in your examples the files are all .py files - are there stubs for the external libraries? If so, can you change the stubs to have explicit re-exports?

the library i'm using has types defined in its .py files, but i'm pretty sure it would behave the same if they were stubs. i also can't really fix them without making stubs for the entire thing which would be a waste of time because they're already typed

JukkaL pushed a commit that referenced this issue Oct 31, 2022
Fixes some of #13965, fixes #12749

We also need to modify attribute access logic (this is the TODO in the
PR), which is a little trickier. But cases like #13933 convinced me it's
worth making this change, even before I get around to figuring that out.
@whai-kung
Copy link

using __all__ = ["Foo"] mypy will know about it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants