Skip to content

PY-IMPO0005 · import_module_depth

Measure the named module depth of one import statement.

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

Count the dot-separated names in the module an import states. Leading relative dots do not name modules and therefore add nothing. Every statement is measured once even when it imports several bindings, since the module path is shared by the whole statement.

Each finding names the import statement and its named module depth. The returned value is that depth. A project policy owns the ceiling, which defaults to three components.

A bare relative import such as from .. import value has no named component and returns zero. Relative level is checked separately by PY-IMPO0004 because climbing and naming are different properties.

Bad

`from library.internal.transport.http import Client` returns `4`.
Good

from ...transport.http import Client returns 2, ignoring the leading relative dots.

  • Cites “The Python Language Reference”, the import statement
  • Cites “A Philosophy of Software Design”, information hiding and navigation cost