-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[pyflakes] Fix allowed-unused-imports matching for top-level modules (F401)
#20115
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
[pyflakes] Fix allowed-unused-imports matching for top-level modules (F401)
#20115
Conversation
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.
Thank you! I just had a couple of suggestions about the tests, but this looks great to me.
Do you want to test if this fixes #15705 as well? There's no need to extend the PR if not, I just thought it sounded related and had a chance of fixing it already.
|
|
Thank you for the review. I have added a simple test case
I want to try it and I guess it takes some time to fix it, so can I work on it in a different pull request? |
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.
Looks great, just one clarification on the test.
I want to try it and I guess it takes some time to fix it, so can I work on it in a different pull request?
That sounds good! I think your fix here might resolve that issue too without any other code changes, but it makes sense to add a test in a separate PR even so. No pressure to work on this, just an idea :)
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.
Thank you!
pyflakes] Fix allowed unused imports matching for top-level modulespyflakes] Fix allowed-unused-imports matching for top-level modules (F401)
* main: Fix mdtest ignore python code blocks (#20139) [ty] add support for cyclic legacy generic protocols (#20125) [ty] add cycle detection for find_legacy_typevars (#20124) Use new diff rendering format in tests (#20101) [ty] Fix 'too many cycle iterations' for unions of literals (#20137) [ty] No boundness analysis for implicit instance attributes (#20128) Bump 0.12.11 (#20136) [ty] Benchmarks for problematic implicit instance attributes cases (#20133) [`pyflakes`] Fix `allowed-unused-imports` matching for top-level modules (`F401`) (#20115) Move GitLab output rendering to `ruff_db` (#20117) [ty] Evaluate reachability of non-definitely-bound to Ambiguous (#19579) [ty] Introduce a representation for the top/bottom materialization of an invariant generic (#20076) [`flake8-async`] Implement `blocking-http-call-httpx` (`ASYNC212`) (#20091) [ty] print diagnostics with fully qualified name to disambiguate some cases (#19850) [`ruff`] Preserve relative whitespace in multi-line expressions (`RUF033`) (#19647)
…les (`F401`) (astral-sh#20115) <!-- Thank you for contributing to Ruff/ty! To help us out with reviewing, please consider the following: - Does this pull request include a summary of the change? (See below.) - Does this pull request include a descriptive title? (Please prefix with `[ty]` for ty pull requests.) - Does this pull request include references to any relevant issues? --> ## Summary <!-- What's the purpose of the change? What does it do, and why? --> Fixes astral-sh#19664 Fix allowed unused imports matching for top-level modules. I've simply replaced `from_dotted_name` with `user_defined`. Since QualifiedName for imports is created in crates/ruff_python_semantic/src/imports.rs, I guess it's acceptable to use `user_defined` here. Please tell me if there is better way. https://github.com/astral-sh/ruff/blob/0c5089ed9e180da7bc76733ffe1a1d132e9142b0/crates/ruff_python_semantic/src/imports.rs#L62 ## Test Plan <!-- How was it tested? --> I've added a snapshot test `f401_allowed_unused_imports_top_level_module`.
Summary
Fixes #19664
Fix allowed unused imports matching for top-level modules.
I've simply replaced
from_dotted_namewithuser_defined. Since QualifiedName for imports is created in crates/ruff_python_semantic/src/imports.rs, I guess it's acceptable to useuser_definedhere. Please tell me if there is better way.ruff/crates/ruff_python_semantic/src/imports.rs
Line 62 in 0c5089e
Test Plan
I've added a snapshot test
f401_allowed_unused_imports_top_level_module.