pyflakes icon indicating copy to clipboard operation
pyflakes copied to clipboard

fix: support type annotation of recursive data structure in local scope

Open PrettyWood opened this issue 5 years ago • 1 comments

Hi everyone ! This is my first contribution so the whole code is still pretty new to me. While working on pydantic, I encountered a false positive and saw there was already an opened issue. I hence decided to give it a go!

closes #567

PrettyWood avatar Dec 25 '20 13:12 PrettyWood

Ok so I ran this against a bunch of typed code, I can't really explain this difference but I boiled this down from a change in pandas:

from typing import TYPE_CHECKING
from typing import Union

if TYPE_CHECKING:
    from x import Y

def f():
    x: Union[int, "Y"]

    if f:
        from x import Y
        return Y()

Before this produced no errors, but after your PR it produces the following:

$ python3 -m pyflakes t.py
t.py:5:5 'x.Y' imported but unused
t.py:11:9 redefinition of unused 'Y' from line 5

asottile avatar Jan 04 '21 21:01 asottile

via #754

asottile avatar Nov 27 '22 21:11 asottile