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

UP006 autofixes but does not remove the redundant imports if file is __init__.py #1029

Closed
LefterisJP opened this issue Dec 4, 2022 · 5 comments

Comments

@LefterisJP
Copy link

LefterisJP commented Dec 4, 2022

This is with ruff==0.0.155

Consider the following file as an __init.py__ somewhere in a code

from typing import Dict, List, Tuple


def foo(a: Dict) -> None:
    pass

def boo(b: List) -> None:
    pass

def goo(c: Tuple) -> None:
    pass

Running ruff --fix turns it into

from typing import Dict, List, Tuple


def foo(a: dict) -> None:
    pass

def boo(b: list) -> None:
    pass

def goo(c: tuple) -> None:
    pass

with the output:

Found 3 error(s) (3 fixed).
__init__.py:1:20: F401 `typing.Dict` imported but unused and missing from `__all__`
__init__.py:1:26: F401 `typing.List` imported but unused and missing from `__all__`
__init__.py:1:32: F401 `typing.Tuple` imported but unused and missing from `__all__`

If the file is not named __init__.py it correctly also removes the unused import. I suspect it has something to do with the internals and how __all__ works in __init__.py

@charliermarsh
Copy link
Member

Yeah, this was an intentional change but I think this behavior should be configurable and perhaps opt-in.

@charliermarsh
Copy link
Member

More context: #484

@charliermarsh
Copy link
Member

I'll just make it a setting, seems easier.

@LefterisJP
Copy link
Author

Yeah, this was an intentional change but I think this behavior should be configurable and perhaps opt-in.

I see. Reading 484 I kind of get how this happened. Happened only once for me and then fixed it, so not a big deal. Configuration option sounds cool

@charliermarsh
Copy link
Member

I believe this is now fixed.

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