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

Exporting type aliases for DtypeLike, ShapeLike and ArrayLike #13

Closed
shoyer opened this issue Mar 6, 2018 · 5 comments
Closed

Exporting type aliases for DtypeLike, ShapeLike and ArrayLike #13

shoyer opened this issue Mar 6, 2018 · 5 comments

Comments

@shoyer
Copy link
Member

shoyer commented Mar 6, 2018

These would indicate anything NumPy can coerce into the respective type:

  • DtypeLike can be coerced into/with np.dtype
  • ShapeLike can be coerced into Tuple[int, ...]
  • ArrayLike can be coerced into np.ndarray with np.array

See #10 for (currently private) aliases _DtypeLike and _ShapeLike.

It would be nice to export these publicly for the benefit of downstream users.

The main complication is that this would likely also require adding these aliases to NumPy itself. Potentially, this could be unnecessary with from __future__ import annotations in Python 3.7 (PEP 564).

@JelleZijlstra
Copy link

Another option is for this repo to define a separate package called numpy_typing or similar that includes a .py defining these, so that users could do from numpy_typing import DtypeLike. With PEP 561 implemented, mypy should be able to pick up the definitions of the aliases from numpy_typing.

@shoyer
Copy link
Member Author

shoyer commented Mar 6, 2018

@JelleZijlstra That's a great alternative! Yes, we should definitely try the separate numpy_typing package to avoid the need to make upstream changes in NumPy yet.

@flying-sheep
Copy link

@person142
Copy link
Member

This can be done without adding a separate package and without from __future__ import annotations (though that is certainly the neatest solution); the annotation just needs to be 'np.ShapeLike' (e.g. a string).

@person142
Copy link
Member

I think we resolved all the issues here in #66.

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

No branches or pull requests

4 participants