Star import reveals internal names when __all__ omits or misspells entries
0 reputation · 07 Nov 2022, 22:51 UTC
Symptom
When a module defines __all__ but includes a name that is not actually defined in its namespace, the star import (from module import *) succeeds at definition time and only raises an AttributeError when a consumer attempts the import.
This delayed failure makes it difficult to catch typos during development or static analysis, and it leaves the public API contract ambiguous for tooling that relies on __all__ to determine exported symbols.
The language reference does not require validation of __all__ entries at module definition, leaving the behavior as an unresolved design point.
What mechanisms could enforce early validation of __all__ entries? Should linters flag undefined or misspelled names in __all__? Is there a way to make the import statement raise an error at module load time when __all__ contains unknown identifiers?