Skip to content

feature: include explicit re-exports #306

@DetachHead

Description

@DetachHead

Is your feature request related to a problem? Please describe.

in python, it's common give an import an alias of the same name to indicate to type checkers that it's an explicit re-export. see here

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. (UPDATE: To clarify, the intention here is that only names imported using the form X as X will be exported, i.e. the name before and after as must be the same.)

note that it says stub files, but this documentation seems to have been written before it was common practice to have type annotations in your source code. type checkers such as pyright and mypy will report an error if the user imports a symbol from a module that it was not either defined in or "re-exported" in regardless of whether it's a stub file or not

for example:

# _private/foo.py

def foo():
    """this function is part of the public api"""
def bar():
    """this function is not"""
# public.py

# this is an explicit re-export, which means the user is supposed to import it from here
# instead of the private module
from _private.foo import foo as foo

# this is not an explicit re-export, indicating that it's only imported within this module to be used internally
from _private.foo import bar
# something_else.py

from public import foo # no error
from public import bar # error: this symbol is not explicitly re-exported from this module

Describe the solution you'd like

when a symbol from a private module is imported into a public module, it should appear in the rendered docs

Describe alternatives you've considered

Additional context

Metadata

Metadata

Assignees

Labels

featureNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions