Skip to content

Module re-exports in stub files not handled correctly #3681

Closed
@Michael0x2a

Description

@Michael0x2a

Mypy currently handles module re-exports in stub files the same way it handles them with regular Python files. That is, any symbol imported at the global level is available for re-export. However, PEP 484 contains the following lines in the section on stub files:

  • Modules and variables imported into the stub are not considered exported from the stub unless the import uses the import ... as ... form or the equivalent from ... import ... as ... form.
  • However, as an exception to the previous bullet, all objects imported into a stub using from ... import * are considered exported. (This makes it easier to re-export all objects from a given module that may vary by Python version.)

I suspect this may be a bit tricky to implement cleanly because iirc, mypy currently doesn't have a mechanism that lets symbols be defined inside a module while being hidden outside (in part because Python itself doesn't really have such a mechanism). Also, my "this might do weird things with incremental mode" senses are tingling.

For context, this issue came up in this pull request: python/typeshed#1471

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions