8000 ENH: make typing module available at runtime by person142 · Pull Request #16558 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

ENH: make typing module available at runtime #16558

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 17, 2020
Merged
Prev Previous commit
DOC: add reference to Python issue about buffer protocols
  • Loading branch information
person142 committed Jun 17, 2020
commit d985e8ca2fca154d3770c842a2da1ba6dc3aaf1c
6 changes: 4 additions & 2 deletions numpy/typing/_array_like.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ def __array__(self, dtype: DtypeLike = ...) -> ndarray: ...

# TODO: support buffer protocols once
#
# https://github.com/python/typing/issues/593
# https://bugs.python.org/issue27501
#
# is resolved. See also the mypy issue:
#
# is resolved.
# https://github.com/python/typing/issues/593
ArrayLike = Union[bool, int, float, complex, _SupportsArray, Sequence]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to support buffer protocols, but Python's typing doesn't support that yet. In the meantime I would suggest adding memoryview and a comment referencing python/typing#593

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since memoryviews are Sequences we do allow them currently, e.g.

import numpy as np

x = b'foobar'
v = memoryview(x)
np.array(v)

passes mypy. I will add the comment though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add a test explicitly for memoryviews though; I'll open an issue.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd highly recommend commenting on this B.P.O issue asking for support for a Buffer protocol in typing, as that is the better place than the typing issue: https://bugs.python.org/issue27501

0