Skip to content

Python · architecture

no-first-party-private-import

python:no-first-party-private-import

Code imports a private name or module from another first-party package.

Code
SARJ048
Default
error
Fix
none
Languages
python

Why

Cross-package private imports couple callers to internals instead of a public surface the owning package can maintain.

Fix

Export the capability under a public name or move the caller behind an existing public function.

Before / after

Executed by this rule’s unit tests.

Before

Service imports another package's private helper

.git/keep
fixture
python/core/core/__init__.py

python/core/core/helpers.py
def _decode(value):
    return value
python/core/pyproject.toml
[project]
name = "core"
python/service/pyproject.toml
[project]
name = "service"
python/service/service/__init__.py

python/service/tests/test_api.py · focus
from core.helpers import _decode

After

Service imports a public helper

.git/keep
fixture
python/core/core/__init__.py

python/core/core/helpers.py
def decode(value):
    return value
python/core/pyproject.toml
[project]
name = "core"
python/service/pyproject.toml
[project]
name = "service"
python/service/service/__init__.py

python/service/tests/test_api.py · focus
from core.helpers import decode

Limits

  • First-party ownership is resolved from repository package manifests and source trees.
  • Relative imports, public and dunder names, third-party and standard-library imports, and supported compiled extensions are excluded.