nptyping icon indicating copy to clipboard operation
nptyping copied to clipboard

Compatibility issues with flake8

Open friggog opened this issue 2 years ago • 2 comments

After the syntax changes in 2.0 flake8 now gives false positives - I believe this is a pyflakes issue but reporting here too for awareness See: https://github.com/PyCQA/pyflakes/issues/687

def unproject(points_2d: NDArray[Shape["N, 2"], Float], camera_object: Camera) -> NDArray[Shape["N, 3"], Float]:
    ....

Throws

F722 syntax error in forward annotation 'N, *'
F821 undefined name 'N'

friggog avatar Apr 11 '22 15:04 friggog

Thank you for reporting this.

pyflakes gives this false positive because it does not deduce where Shape is coming from (as e.g. MyPy does). It looks no further than that single line and concludes that no type hint other than typing.Literal may contain a string value. Fun fact: Shape actually is an alias for Literal...

I'm afraid there's little nptyping can do here. I think you're left with 2 options:

  1. make pyflakes ignore that line or that/those code/codes in general;
  2. use typing.Literal instead of nptyping.Shape: this is accepted by nptyping (but it looks less nice imo).

ramonhagenaars avatar Apr 11 '22 18:04 ramonhagenaars

I'm encountering the same issue in this post.

RemyLau avatar Aug 10 '22 17:08 RemyLau