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

[pyflakes] Fix check of unused imports #13965

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

gpilikin
Copy link

Summary

Fixed incorrect detection of unused imports with submodules. They were always marked as used even though they are not.

For example:

import multiprocessing.pool
import multiprocessing.process  # marked as used

tp = multiprocessing.pool.ThreadPool()
...

The solution:

  • Added checking all possible attribute combinations for similar imports and marking them as used ("foo.bar", "foo" etc), if there are none, the root module itself should be marked as used.
  • Added checks on the use of all imports with submodules.

Test Plan

cargo test

Closes: #60

@gpilikin gpilikin marked this pull request as ready for review October 29, 2024 05:40
@gpilikin gpilikin changed the title [pyflakes] Fix check of unused imports. [pyflakes] Fix check of unused imports Oct 29, 2024
Fix error when importing modules without submodules.
Add attribute check for similar imports with submodule.
@dhruvmanila dhruvmanila added the bug Something isn't working label Nov 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Handle multiple unused submodule imports
2 participants