Skip to content

PY-MODU0004 · explicit_all_only_in_initializer

Keep explicit package export lists inside package initializers.

This is a deterministic rule for python. Read its implementation.

Report an ordinary Python module that assigns or extends __all__. A defining module already publishes its public names through ordinary Python visibility, while a package initializer is the one place that combines sibling definitions into a package surface.

Each finding covers the complete module that declares __all__. The Boolean value is true only when that declaration appears outside __init__.py.

Package initializers may build __all__ through assignments, annotations, or augmented assignments. A generated compatibility facade can exclude its exact path while the migration that requires it remains active.

Bad

`service.py` containing `__all__ = [\"Client\"]` returns `true`.
Good

The same declaration in service/__init__.py returns false.

  • Cites “The Python Language Reference”, the import statement. Open reference
  • Cites “PEP 8, Style Guide for Python Code”, Public and Internal Interfaces. Open reference