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
fixture
def _decode(value):
return value
[project]
name = "core"
[project]
name = "service"
from core.helpers import _decode
After
Service imports a public helper
fixture
def decode(value):
return value
[project]
name = "core"
[project]
name = "service"
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.