machinalis / mypy-data

mypy typesheds for the Python data stack
BSD 3-Clause "New" or "Revised" License
86 stars 23 forks source link

Python interpreter error with typed hints #17

Open DasVinch opened 7 years ago

DasVinch commented 7 years ago

I've grown very interested in obtaining and expanding numpy stubs.

However, when it comes to typed ndarrays, I've come to this issue

def a_function(x: np.ndarray[np.float32]) -> None:
    print('Foo')

is valid for mypy, however the python3 interpreter fails (logically. Here in interpreter, same for type hints in modules.).

In [4]: np.ndarray[np.float32]
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-4-d3b20ca13ba6> in <module>()
----> 1 np.ndarray[np.float32]

TypeError: 'type' object is not subscriptable

Question is, how to circumvent this problem ? a typing package style protocol requiring arguments dtype, shape, etc... ?