pyre-check icon indicating copy to clipboard operation
pyre-check copied to clipboard

Detect import problems with __future__

Open tspence opened this issue 2 years ago • 0 comments

Pyre Feature Request

Detect when the import of from __future__ import annotations is not the first import in a file and create an error for it.

Is your feature request related to a problem? Please describe.

My library has nested data models similar to the following:

from dataclasses import dataclass
from __future__ import annotations

class Foo:
    children: list[Foo] | None = None

Pyre accepts this, but when run in Python, it reports the following error:

  File "C:\myfiles\foo.py", line 16
    from __future__ import annotations
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: from __future__ imports must occur at the beginning of the file

Describe the solution you'd like Pyre should report an error if this import statement is not at the beginning of the file.

tspence avatar Mar 14 '22 23:03 tspence