numpy/numpy-stubs

Don't allow initializing `generic`

person142 opened this issue · 3 comments

Follow up to #72.

The following currently passes mypy:

import numpy as np

reveal_type(np.generic(1))

but you can't actually create instances of generic:

>>> import numpy as np
>>> np.generic(1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: cannot create 'numpy.generic' instances

We should

  • Add constructors specifically to the classes that can be instantiated (np.float64 etc)
  • Remove the constructor from generic
BvB93 commented

The same issue seems to apply to np.number and np.complexfloating:

>>> import numpy as np

>>> np.number(1)
Traceback (most recent call last):
   ...
TypeError: cannot create 'numpy.number' instances

>>> np.complexfloating(1)
Traceback (most recent call last):
   ...
TypeError: cannot create 'numpy.complexfloating' instances
BvB93 commented

I've created a pull request addressing the issue at #80.

Closed by #80.