diff options
author | Bas van Beek <b.f.van.beek@vu.nl> | 2021-05-24 14:45:49 +0200 |
---|---|---|
committer | Bas van Beek <b.f.van.beek@vu.nl> | 2021-05-27 17:24:04 +0200 |
commit | 66fa0481c0dd85d4f90dc56afe3f1b42b96945ad (patch) | |
tree | 127daaf75e88eeb5e55bc876e2844f2970ec9700 /numpy/typing/_array_like.py | |
parent | 89da72353f5e282a36a8e9ad9012400dbe452ced (diff) | |
download | numpy-66fa0481c0dd85d4f90dc56afe3f1b42b96945ad.tar.gz |
ENH: Add a global constant to `numpy.typing` denoting whether or not `typing_extensions` is available
Diffstat (limited to 'numpy/typing/_array_like.py')
-rw-r--r-- | numpy/typing/_array_like.py | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/numpy/typing/_array_like.py b/numpy/typing/_array_like.py index 2283c98d7..2b823ecc0 100644 --- a/numpy/typing/_array_like.py +++ b/numpy/typing/_array_like.py @@ -21,23 +21,20 @@ from numpy import ( bytes_, ) +from . import _HAS_TYPING_EXTENSIONS +from ._dtype_like import DTypeLike + if sys.version_info >= (3, 8): from typing import Protocol - HAVE_PROTOCOL = True -else: - try: - from typing_extensions import Protocol - except ImportError: - HAVE_PROTOCOL = False - else: - HAVE_PROTOCOL = True +elif _HAS_TYPING_EXTENSIONS: + from typing_extensions import Protocol _T = TypeVar("_T") _ScalarType = TypeVar("_ScalarType", bound=generic) _DType = TypeVar("_DType", bound="dtype[Any]") _DType_co = TypeVar("_DType_co", covariant=True, bound="dtype[Any]") -if TYPE_CHECKING or HAVE_PROTOCOL: +if TYPE_CHECKING or _HAS_TYPING_EXTENSIONS: # The `_SupportsArray` protocol only cares about the default dtype # (i.e. `dtype=None` or no `dtype` parameter at all) of the to-be returned # array. |