Skip to content

PEP 561: Clarify symbols imported into __init__.py #2768

@crusaderky

Description

@crusaderky

PEP-484 contains the following paragraph, which is specific to .pyi stubs:

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

PEP-561 introduced the option to use regular .py files as external type declarations, by simply adding py.typed to a package. This however causes confusion about whether top-level __init__.py files should adhere to the paragraph above in order to have their symbols exported or not.

My personal interpretation is no, as it makes things extremely unreadable and a full python module is not a stub; also this is contrary to the best practice adopted by virtually all libraries I've observed. However, pyright interpreted it in the opposite way and will ignore symbols not imported in the above way. An authoritative clarification in PEP-561 would be appreciated.

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