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

Flag unused imports even with redefinition #300

Closed
charliermarsh opened this issue Oct 2, 2022 · 6 comments
Closed

Flag unused imports even with redefinition #300

charliermarsh opened this issue Oct 2, 2022 · 6 comments

Comments

@charliermarsh
Copy link
Member

Given this code:

import os
import os

We return:

Found 1 error(s).
foo.py:2:1: F401 `os` imported but unused

Flake8 does this:

foo.py:2:1: F811 redefinition of unused 'os' from line 1
foo.py:2:1: F401 'os' imported but unused

My preference would be:

Found 2 error(s).
foo.py:1:1: F401 `os` imported but unused
foo.py:2:1: F401 `os` imported but unused
@Cxxshyy
Copy link

Cxxshyy commented Oct 18, 2022

hi im fairly new to rust but can have a go at this so can you first tell me what file handle this and ill take a look

@charliermarsh charliermarsh removed the good first issue Good for newcomers label Oct 18, 2022
@charliermarsh
Copy link
Member Author

@Cxxshyy - Awesome! I marked this as good first issue a few weeks back but I think it may be deceptively tricky. (It requires some extra book-keeping to understand when an import "redefines" another import, since you can have imports split across if-else blocks and so on.)

If you're looking for a place to contribute, a good starting point might be to take a rule you like from flake8-bugbear and add it to Ruff (#389). I wrote some instructions on a similar issue in here that would be helpful for understanding how to add a new check. Does that look interesting to you?

@Cxxshyy
Copy link

Cxxshyy commented Oct 18, 2022

yes that looks interesting ill have a look at this tomorrow

@charliermarsh
Copy link
Member Author

Cool, don't hesitate to ask questions, I'd love to be helpful.

@Cxxshyy
Copy link

Cxxshyy commented Oct 18, 2022

will do thanks

@charliermarsh
Copy link
Member Author

This got resolved when we added the redefined-while-unused checks.

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

No branches or pull requests

2 participants