autoflake
autoflake copied to clipboard
Autoflake removes imports that are used as the string bound of a type variable
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.
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?
@PeterJCLaw Thanks, done!