Skip to content
This repository was archived by the owner on Jun 10, 2020. It is now read-only.

Don't allow initializing generic #77

Closed
person142 opened this issue May 1, 2020 · 3 comments
Closed

Don't allow initializing generic #77

person142 opened this issue May 1, 2020 · 3 comments

Comments

@person142
Copy link
Member

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
Copy link
Member

BvB93 commented May 1, 2020

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
Copy link
Member

BvB93 commented May 14, 2020

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

@person142 person142 added this to the before-merging-into-numpy milestone May 24, 2020
person142 pushed a commit that referenced this issue Jun 6, 2020
This pull request addresses the issues raised in
#77: constructors were
previously available for ``np.generic`` and a number of its
subclasses, many of which could not actually be instantiated.
@person142
Copy link
Member Author

Closed by #80.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants