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

Autoflake removes imports that are used as the string bound of a type variable #84

Open
NeilGirdhar opened this issue Jan 4, 2021 · 2 comments

Comments

@NeilGirdhar
Copy link

NeilGirdhar commented Jan 4, 2021

This works great:

from typing import Any

x: 'Any' = 2

But this doesn't work:

from typing import Any, TypeVar


T = TypeVar('T', bound='Any')

def f(x: T):
    pass

String annotations are sometimes required here when Any is used with a generic type that is conditionally imported as illustrated in #76. Such an annotation must be a string, which means that Any must be a string too. Please consider treating the bound of a TypeVar as an annotation.

@PeterJCLaw
Copy link

Running pyflakes on your example code also finds that typing.Any is unused. Since autoflake relies on pyflakes, I suspect this is a pyflakes issue -- maybe report this there?

@NeilGirdhar
Copy link
Author

@PeterJCLaw Thanks, done!

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