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

[Bug] unused typing imports are not auto-fixed when pyupgrade option is selected #866

Closed
ukalwa opened this issue Nov 21, 2022 · 5 comments
Labels
bug Something isn't working

Comments

@ukalwa
Copy link

ukalwa commented Nov 21, 2022

Ruff version: 0.0.132
Ruff configuration: Default
Python version: 3.10

Simple reproduction

# test.py
from typing import List
def test_sum_of_sequence(numbers: List[int]) -> int:
    return sum(numbers)
# pyproject.toml
[tool.ruff]
select = ["E", "F", "U"]
target-version = "py310"

When I ran ruff test.py --fix, the file changed to:

from typing import List # unused import
def test_sum_of_sequence(numbers: list[int]) -> int: # Notice typing.List changed to built-in list
    return sum(numbers)

I would expect it to also remove unused imports from typing import List. As a workaround I run the command again to remove unused imports but it would be great if ruff can do it automatically.

Let me know if there is anything I could do to help.

Thank you for this amazing package. It is super fast and works great!

@charliermarsh charliermarsh added the bug Something isn't working label Nov 21, 2022
@charliermarsh
Copy link
Member

Thank you for the kind words, and for the detailed report!

This is sort of a "known" bug but definitely something I'd like to fix. (This would be resolved automatically if we change Ruff to iteratively fix + re-run until the code stabilizes, as suggested in #660.)

@ukalwa
Copy link
Author

ukalwa commented Nov 22, 2022

Yes, that makes sense.

If no one hasn’t started working on this, I can give it a try if you can point me in the right direction.

@charliermarsh
Copy link
Member

@ukalwa - I started on this last night! Sorry to step on your toes!

@ukalwa
Copy link
Author

ukalwa commented Nov 22, 2022

Cool, no worries 😀

@charliermarsh
Copy link
Member

Should be fixed by #875.

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

No branches or pull requests

2 participants