autoflake icon indicating copy to clipboard operation
autoflake copied to clipboard

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

Open NeilGirdhar opened this issue 4 years ago • 2 comments

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.

NeilGirdhar avatar Jan 04 '21 00:01 NeilGirdhar

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 avatar Feb 20 '21 10:02 PeterJCLaw

@PeterJCLaw Thanks, done!

NeilGirdhar avatar Feb 24 '21 06:02 NeilGirdhar