PyCQA / pyflakes

A simple program which checks Python source files for errors
https://pypi.org/project/pyflakes
MIT License
1.36k stars 178 forks source link

F821 on forward ref #768

Closed Dreamsorcerer closed 1 year ago

Dreamsorcerer commented 1 year ago

Seems that a forward ref is triggering F821, unless I'm missing something obvious.

Code:

    class TestMany(base):  # type: ignore[misc,valid-type]
        __tablename__ = "many"
        id: Mapped[int] = mapped_column(primary_key=True)
        ones: Mapped[list["TestOne"]] = relationship()  # F821 undefined name 'TestOne'

    class TestOne(base):  # type: ignore[misc,valid-type]
        __tablename__ = "one"
        id: Mapped[int] = mapped_column(primary_key=True)
        many_id: Mapped[int] = mapped_column(sa.ForeignKey(TestMany.id))

Run through pre-commit with flake8==6.0.0: https://github.com/aio-libs/aiohttp-admin/blob/relationships/.pre-commit-config.yaml#L41 https://github.com/aio-libs/aiohttp-admin/actions/runs/4377267582/jobs/7660514842

asottile commented 1 year ago

there's a dupe, try the latest on main