Skip to content

no-first-party-private-import

A first-party consumer imports a private name or private module across its package boundary.

Why

Private imports couple consumers, including white-box tests, to internals instead of a public surface the owning package can maintain.

Fix

Use the owning package's public API. Test public behavior; promote an internal only when it deserves an explicit reusable contract.

Examples

Before — flagged Service imports another package's private helper
.git/keep
fixture
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/consumer.py
from core.helpers import _decode
After — preferred Service imports a public helper
.git/keep
fixture
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/consumer.py
from core.helpers import decode