Skip to content

PY-IMPO0006 · bypassed_public_import

Count imports that bypass the shortest explicit project package surface.

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

Resolve every explicit __all__ export to its defining declaration. When several packages export the same declaration, keep the shortest public route. Report a direct import of the defining module when that shorter route already exists.

Each finding names the import expression, the preferred package and name, and the exact import line. The value is the number of imports bypassing a shorter explicit public route.

Imports within the exporting initializer are excluded because they construct the public route. Imports from modules inside either the exporting package or the defining package are excluded because they are implementation details and routing them through a facade can create import cycles. A declaration with no explicit package export has no route to prefer. External packages are not inspected, since their installed public surface is outside the repository graph. The fix changes the module path only when every binding in the statement reaches the same facade, its existing relative dots can reach that facade, and the facade cannot reach the importing module through the import graph. Every other bypass remains a finding for review.

Bad

`from mcmr.project.configuration import ScanConfiguration` bypasses an explicit
`mcmr.ScanConfiguration` export.
Good

from mcmr import ScanConfiguration uses the shortest explicit surface.

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