PY-IMPO0005 · import_module_depth
Measure the named module depth of one import statement.
This is a deterministic rule for python. Read its implementation.
Definition
Section titled “Definition”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.
Evidence
Section titled “Evidence”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.
Exceptions
Section titled “Exceptions”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.
Examples
Section titled “Examples”Bad
`from library.internal.transport.http import Client` returns `4`.
Goodfrom ...transport.http import Client returns 2, ignoring the leading relative dots.
References
Section titled “References”- Cites “The Python Language Reference”, the import statement
- Cites “A Philosophy of Software Design”, information hiding and navigation cost