Skip to content

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

Closed

Description

@DetachHead
# 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)

Activity

  1. KotlinIsland commented on May 8, 2022

    @KotlinIsland
    Contributor

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

    [[tool.mypy.overrides]]
    module = "thepackage.*"
    implicit_reexport = true
  2. Zeckie commented on May 21, 2022

    @Zeckie

    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?

  3. DetachHead commented on May 22, 2022

    @DetachHead
    ContributorAuthor

    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

  4. added a commit that references this issue on Oct 31, 2022
    8c69124
  5. whai-kung commented on Mar 15, 2023

    @whai-kung

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions