python / python/mypy

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

Open
#21,328 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the report with a package whose init.pyi uses from .submod import * and lists submodules in __all__; start by tracing stubtest's handling of these exports. Done means stubtest recognizes runtime-bound submodules without emitting one missing-submodule diagnostic per entry, with regression coverage for the case.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.