-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[pylint
] Implement import-private-name
(C2701
)
#5920
Conversation
PR Check ResultsEcosystem✅ ecosystem check detected no changes. BenchmarkLinux
Windows
|
Most of the triggers from the ecosystem check seem to be in test suites, which is fine. The others seem to be false positives from not checking if a module is importing something from itself. |
Looking through the ecosystem check, the flagged violations are all
|
pylint
] Impliment import-private-name
(C2701
)pylint
] Implement import-private-name
(C2701
)
Related: #6114. |
513614f
to
542d555
Compare
@tjkuson Is there anything I can do to help moving this forward? Or is all that's left to to a rebase and the review of @charliermarsh? |
Wow, I forgot about this PR! If I recall correctly, this PR was working but required users to specify @charliermarsh I don't mind rebasing and tweaking the PR if you are open to it being merged (I have probably improved with Rust over these months). |
If wanted I'd be open to test it prior merging. Might a note in the docs regarding this behavior be sufficient? Anyway, thanks for the fast response, let me know when I can help :) |
I think we probably do need to support the type annotation thing, since we changed |
How does this compare to the flake8-self rules? |
Sure! It should be a simple change if you are still open to the rule being merged.
from foo import _bar
bar = _bar(...) won't trigger the rule, but would trigger |
Thanks @tjkuson. I assume they would both trigger on: from foo import _bar
bar = _bar._baz(...) And that only flake8-self would trigger on: from foo import bar
bar = bar._baz(...) Is that right? |
Yes! Are you thinking of merging them as one rule? |
@tjkuson - Eventually maybe... For now, I'm okay with them being separate as long as they don't have overlap. |
95d3ae8
to
63f6fee
Compare
Rebased to |
|
code | total | + violation | - violation | + fix | - fix |
---|---|---|---|---|---|
PLC2701 | 473 | 473 | 0 | 0 | 0 |
S101 | 230 | 0 | 230 | 0 | 0 |
Q000 | 150 | 0 | 150 | 0 | 0 |
E265 | 104 | 0 | 104 | 0 | 0 |
D102 | 63 | 0 | 63 | 0 | 0 |
ANN101 | 60 | 0 | 60 | 0 | 0 |
PLR6301 | 60 | 0 | 60 | 0 | 0 |
PLR2004 | 47 | 0 | 47 | 0 | 0 |
SLF001 | 38 | 0 | 38 | 0 | 0 |
E402 | 23 | 0 | 23 | 0 | 0 |
C408 | 22 | 0 | 22 | 0 | 0 |
E275 | 18 | 0 | 18 | 0 | 0 |
PT011 | 17 | 0 | 17 | 0 | 0 |
E231 | 16 | 0 | 16 | 0 | 0 |
E261 | 15 | 0 | 15 | 0 | 0 |
ANN001 | 15 | 0 | 15 | 0 | 0 |
ERA001 | 14 | 0 | 14 | 0 | 0 |
D101 | 12 | 0 | 12 | 0 | 0 |
N801 | 12 | 0 | 12 | 0 | 0 |
E203 | 8 | 0 | 8 | 0 | 0 |
E702 | 7 | 0 | 7 | 0 | 0 |
B018 | 7 | 0 | 7 | 0 | 0 |
I001 | 7 | 0 | 7 | 0 | 0 |
D100 | 7 | 0 | 7 | 0 | 0 |
INP001 | 7 | 0 | 7 | 0 | 0 |
D103 | 6 | 0 | 6 | 0 | 0 |
A002 | 6 | 0 | 6 | 0 | 0 |
E202 | 4 | 0 | 4 | 0 | 0 |
E201 | 4 | 0 | 4 | 0 | 0 |
N802 | 3 | 0 | 3 | 0 | 0 |
FIX002 | 2 | 0 | 2 | 0 | 0 |
TD002 | 2 | 0 | 2 | 0 | 0 |
TD003 | 2 | 0 | 2 | 0 | 0 |
PT018 | 2 | 0 | 2 | 0 | 0 |
DTZ001 | 2 | 0 | 2 | 0 | 0 |
PT006 | 1 | 0 | 1 | 0 | 0 |
ANN202 | 1 | 0 | 1 | 0 | 0 |
ANN003 | 1 | 0 | 1 | 0 | 0 |
ARG001 | 1 | 0 | 1 | 0 | 0 |
PT012 | 1 | 0 | 1 | 0 | 0 |
ANN201 | 1 | 0 | 1 | 0 | 0 |
PLC0415 | 1 | 0 | 1 | 0 | 0 |
E225 | 1 | 0 | 1 | 0 | 0 |
E241 | 1 | 0 | 1 | 0 | 0 |
PLR0402 | 1 | 0 | 1 | 0 | 0 |
@charliermarsh The PR has been rebased and now forgives private name imports that are used for type annotations! |
CodSpeed Performance ReportMerging #5920 will improve performances by ×4.9Comparing Summary
Benchmarks breakdown
|
Sorry, this is blocked on me, I've just been slow to get to it. |
Great work @tjkuson. |
I'm going to revert this change. It's panicking in the pydantic benchmark run (see https://github.com/astral-sh/ruff/actions/runs/7537305800/job/20516059364?pr=5920). |
Includes fix for incorrect slice in astral-sh#5920.
Summary
Implements
import-private-name
(C2701
) asimport-private-name
(PLC2701
). Includes documentation.Related to #970.
Closes #9138.
PEP 420 namespace package limitation
checker.module_path
doesn't seem to support automatic detection of namespace packages (PEP 420). This leads to 'false' positives (Pylint allows both).Currently, for this to work like Pylint, users would have to manually input known namespace packages.
Test Plan
cargo test