Skip to content

stubtest misses the presence of submodules in the top level of module when from .submod import * used to reexport submodules in __init__.pyi #21328

@jonathandung

Description

@jonathandung

In my package's __init__.py, when I list the names of all my submodules along with the functions imported from them in __all__, such that from pkg import * would make the submodule objects available in the global namespace as well, stubtest thinks the submodules are missing, meaning __all__ is inconsistent with what happens at runtime.

However, python's import machinery means that loading a submodule binds it to the parent module as an attribute with the same name. This is how when you import a submodule in any way, it is accessible by dotted name on the parent module, so there is nothing wrong with including the submodules in my __all__, and in my case an intended behaviour. This is significant since stubtest annoyingly produces one diagnostic per submodule, and including them in allowlist may shadow other issues.

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