Skip to content

Report reaching into third-party internals - #708

Open
ecomodeller wants to merge 2 commits into
mainfrom
ruff-private-import-rule
Open

ecomodeller wants to merge 2 commits into
mainfrom
ruff-private-import-rule

Conversation

@ecomodeller

Copy link
Copy Markdown
Member

Reaching into another package's internals — importing a private name, or reading a private attribute off one of its objects — is outside any deprecation policy and breaks on a patch release, with nothing in CI to notice.

Imports are covered by ruff's PLC2701, which correctly ignores relative imports inside our own package. It is still a preview rule, so preview = true is needed; src/ is already clean under it.

Attribute access has no equivalent. SLF001 is not type-aware — it reports all 75 occurrences in src/ without knowing whose object it is, and 74 are modelskill reading its own attributes, which is ordinary intra-package access. tools/check_third_party_private_access.py narrows SLF001 by name: a member defined somewhere in src/modelskill is ours, anything else belongs to another package. Name-based, not type inference — the script's docstring states what it misses.

That leaves one finding, ds_column._zn on a mikeio Dataset:

src/modelskill/model/dfsu.py:211: _zn

This must merge after #707, which removes that line. Until then just private-access exits 1 and the lint job is red.

The lint job now runs just lint instead of duplicating the ruff invocation inline, so CI and local dev stay in step.

🤖 Generated with Claude Code

Two ways modelskill can depend on another package's internals: importing a
private name, and reading a private attribute off one of its objects. Neither
is covered by any deprecation policy, so both break without warning on a patch
release.

Imports are caught by ruff's PLC2701, which ignores relative imports inside our
own package. It needs preview mode; src/ is already clean under it.

Attribute access has no equivalent rule -- SLF001 flags all 75 occurrences in
src/ without knowing whose object it is, and 74 of those are modelskill reading
its own attributes, which is fine. tools/check_third_party_private_access.py
narrows SLF001 by name: a member we define somewhere in src/modelskill is ours,
anything else belongs to another package. That leaves one finding,
ds_column._zn on a mikeio Dataset in dfsu.py.

The lint job now runs just, so CI and local dev use the same commands.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Comment thread tools/check_third_party_private_access.py Fixed
relative_to raised ValueError for any path outside the repo and the handler
swallowed it silently. is_relative_to asks the question directly.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant