nptyping
nptyping copied to clipboard
Compatibility issues with flake8
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'
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:
- make pyflakes ignore that line or that/those code/codes in general;
- use
typing.Literal
instead ofnptyping.Shape
: this is accepted bynptyping
(but it looks less nice imo).
I'm encountering the same issue in this post.