Skip to content
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 (unused imports) - Help text underlining is confusing #11223

Open
plredmond opened this issue Apr 30, 2024 · 1 comment
Open

F401 (unused imports) - Help text underlining is confusing #11223

plredmond opened this issue Apr 30, 2024 · 1 comment
Labels
rule Implementing or modifying a lint rule

Comments

@plredmond
Copy link
Contributor

In #11168 we noticed that the help text is only underlining the as-name part of an unused import, e.g.

47 | from . import renamed as bees # F401: no fix
   |                          ^^^^ F401
   |
   = help: Remove unused import: `.renamed`

This might be confusing for users and should be fixed.

@plredmond
Copy link
Contributor Author

plredmond commented May 9, 2024

@zanieb I added this issue at your instruction, but I'm not sure that it's required any longer.

I think the justification for only underlining the /binding/ that is unused, and not the whole /statement/ is because of the case where there are multiple bindings in a single statement, some of which are used and some of which aren't.

Here's a fixture test that demonstrates this:

"""__init__.py with __all__ populated by conditional plus-eq
multiple __all__ so cannot offer a fix to add to them
"""
import sys
from . import unused, exported, renamed as bees
if sys.version_info > (3, 9):
from . import also_exported
__all__ = ["exported"]
if sys.version_info >= (3, 9):
__all__ += ["also_exported"]

and its resolution:

---
source: crates/ruff_linter/src/rules/pyflakes/mod.rs
---
__init__.py:8:15: F401 `.unused` imported but unused; consider removing, adding to `__all__`, or using a redundant alias
|
6 | import sys
7 |
8 | from . import unused, exported, renamed as bees
| ^^^^^^ F401
9 |
10 | if sys.version_info > (3, 9):
|
= help: Remove unused import
__init__.py:8:44: F401 `.renamed` imported but unused; consider removing, adding to `__all__`, or using a redundant alias
|
6 | import sys
7 |
8 | from . import unused, exported, renamed as bees
| ^^^^ F401
9 |
10 | if sys.version_info > (3, 9):
|
= help: Remove unused import

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rule Implementing or modifying a lint rule
Projects
None yet
Development

No branches or pull requests

2 participants