ramonhagenaars / nptyping

💡 Type hints for Numpy and Pandas
MIT License
576 stars 29 forks source link

mypy, isinstance, and generics, oh my! #108

Open ewa opened 1 year ago

ewa commented 1 year ago

I don't know if this is user error or a bug, but when I try to typecheck the following code (basically copied from USERDOC.md) with mypy I get an error:

The code:

print(isinstance(np.random.randn(5, 2), NDArray[Shape["5 coordinates, [x, y]"], Any]))

The error

% mypy error_example.py
error_example.py:5: error: Parameterized generics cannot be used with class or instance checks  [misc]
Found 1 error in 1 file (checked 1 source file)

Does anyone have any suggestions?

Here's my configuration info:

ewa-mbp:~/ext/sounder andersoe % pip3 list | grep nptyping
nptyping                   2.5.0
ewa-mbp:~/ext/sounder andersoe % pip3 list | grep mypy
mypy                       1.3.0
mypy-extensions            1.0.0
ewa-mbp:~/ext/sounder andersoe % pip3 list | grep numpy
numpy                      1.24.3
ewa-mbp:~/ext/sounder andersoe % python3 --version
Python 3.11.3

The full code examples is:

import numpy as np
from typing import Any
from nptyping import NDArray, Shape

print(isinstance(np.random.randn(5, 2), NDArray[Shape["5 coordinates, [x, y]"], Any]))