-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
F401 - Recommend adding unused import bindings to __all__
#11314
Conversation
Oops, didn't add clippy to my pre-push hook. Added now. |
|
I swear I have fixed my pre-push hook now. |
...s/ruff_linter__rules__pyflakes__tests__preview__F401_F401_27__all_mistyped____init__.py.snap
Outdated
Show resolved
Hide resolved
crates/ruff_linter/resources/test/fixtures/pyflakes/F401_29__all_pluseq/__init__.py
Outdated
Show resolved
Hide resolved
...lakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F401_F401_24____init__.py.snap
Outdated
Show resolved
Hide resolved
crates/ruff_linter/resources/test/fixtures/pyflakes/F401_29__all_pluseq/__init__.py
Outdated
Show resolved
Hide resolved
Almost there, maybe? @zanieb @AlexWaygood Two unresolved threads left. |
I believe that i've resolved the outstanding requests. @AlexWaygood it might make sense to do a pass over the fixture tests now since there has been some churn, to see if you agree with how each case is resolved? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Much improved, thanks for your patience! A few more comments below.
...linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F401_F401_5.py.snap
Outdated
Show resolved
Hide resolved
...lakes/snapshots/ruff_linter__rules__pyflakes__tests__preview__F401_F401_24____init__.py.snap
Show resolved
Hide resolved
...s/ruff_linter__rules__pyflakes__tests__preview__F401_F401_25__all_nonempty____init__.py.snap
Outdated
Show resolved
Hide resolved
This is ready for review again. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, this is a huge improvement to this rule 🎉
crates/ruff_linter/resources/test/fixtures/pyflakes/F401_26__all_empty/__init__.py
Outdated
Show resolved
Hide resolved
(A few small comments but for clarity no need to wait on my approval to merge.) |
CodSpeed Performance ReportMerging #11314 will degrade performances by 6.83%Comparing Summary
Benchmarks breakdown
|
I suspect the CodSpeed regression is a false positive. |
Maybe it'll re-run after this last pull and resolve (if codespeed updates its comments). |
Rebasing or merging in |
Ah, that's a good point. If we're comparing to |
…ove unnecessary import paths
Rebasing. |
I've updated the PR description to reflect the diff after all review comments. Not sure what to do next. CodeSpeed might be a false-positive, but that should have been mitigated by rebasing. |
&lexer::lex(raw, Mode::Expression).collect::<Vec<_>>(), | ||
&locator, | ||
); | ||
// SUT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does SUT
mean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
system under test -- the test is long so i'm marking the bit that's unit tested
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This acronym was also unfamiliar to me FWIW
I think it's ok to merge personally. |
I'm looking through the changes again just to see if anything sticks out. |
The only thing that stands out is that we're allocating an additional string for |
We could consider using |
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
…e iterator" This reverts commit 548180b.
…ding-name field (named as .name); update fixture test results
Trying out Charlie's suggestion of using only one string in the violation struct. This caused /a lot/ of fixture changes to have cosmetic changes to help text and rule titles. If it doesn't correct the regression I'll revert. |
Ok, that didn't work so I'm going to revert and then merge once tests pass. |
… the binding-name field (named as .name); update fixture test results" This reverts commit 0696df5.
Ok! I've tried (and reverted) both of the suggested performance improvements. Do we want to just merge this? I have no more commits to push. |
Yeah, I'm fine with going ahead and merging. |
#11436) ## Summary * Update documentation for F401 following recent PRs * #11168 * #11314 * Deprecate `ignore_init_module_imports` * Add a deprecation pragma to the option and a "warn user once" message when the option is used. * Restore the old behavior for stable (non-preview) mode: * When `ignore_init_module_imports` is set to `true` (default) there are no `__init_.py` fixes (but we get nice fix titles!). * When `ignore_init_module_imports` is set to `false` there are unsafe `__init__.py` fixes to remove unused imports. * When preview mode is enabled, it overrides `ignore_init_module_imports`. * Fixed a bug in fix titles where `import foo as bar` would recommend reexporting `bar as bar`. It now says to reexport `foo as foo`. (In this case we don't issue a fix, fwiw; it was just a fix title bug.) ## Test plan Added new fixture tests that reuse the existing fixtures for `__init__.py` files. Each of the three situations listed above has fixture tests. The F401 "stable" tests cover: > * When `ignore_init_module_imports` is set to `true` (default) there are no `__init_.py` fixes (but we get nice fix titles!). The F401 "deprecated option" tests cover: > * When `ignore_init_module_imports` is set to `false` there are unsafe `__init__.py` fixes to remove unused imports. These complement existing "preview" tests that show the new behavior which recommends fixes in `__init__.py` according to whether the import is 1st party and other circumstances (for more on that behavior see: #11314).
* setup precommit ruff formatter and linter * fmt * update pipelines * restore import trulens_eval before model_rebuild * rm extraneous files * rm test data * fix explain pipeline * install dev requirements * revert trulens_explain * revert trulens_explain * pr fixes * notebook formatting fixes * docs authorship update * fmt * skip json cause it can't handle comments
Followup on #11168 and resolve #10391
User facing changes
__all__
if a single__all__
list or tuple is found in__init__.py
.__all__
found in the file, fall back to recommending redundant-aliases.__all__
or only one but of the wrong type (non list or tuple) then diagnostics are generated without fixes.fix_title
is updated to reflect what the fix/recommendation is.Subtlety: For a renamed import such as
import foo as bees
, we can generate a fix to addbees
to__all__
but cannot generate a fix to produce a redundant import (because that would break uses of the bindingbees
).Implementation changes
name
field toImportBinding
to contain the name of the binding we want to add to__all__
(important for theimport foo as bees
case). It previously only contained theAnyImport
which can give us information about the import but not the binding.binding
field toUnusedImport
to contain the same. (Naming note: the fieldname
field already existed onUnusedImport
and contains the qualified name of the imported symbol/module)fix_by_reexporting
to branch on the size ofdunder_all: Vec<&Expr>
make_redundant_alias
.add_to_dunder_all
.add_to_dunder_all
and add unit tests.__all__ = []
, nonempty__all__ = ["foo"]
, mis-typed__all__ = None
, plus-eq__all__ += ["foo"]
UnusedImportContext::Init
variant now has two fields: whether the fix is in__init__.py
and how many__all__
were found.Other changes
make_redundant_alias