summaryrefslogtreecommitdiff
path: root/numpy/typing/_char_codes.py
diff options
context:
space:
mode:
authorBas van Beek <b.f.van.beek@vu.nl>2021-05-24 14:45:49 +0200
committerBas van Beek <b.f.van.beek@vu.nl>2021-05-27 17:24:04 +0200
commit66fa0481c0dd85d4f90dc56afe3f1b42b96945ad (patch)
tree127daaf75e88eeb5e55bc876e2844f2970ec9700 /numpy/typing/_char_codes.py
parent89da72353f5e282a36a8e9ad9012400dbe452ced (diff)
downloadnumpy-66fa0481c0dd85d4f90dc56afe3f1b42b96945ad.tar.gz
ENH: Add a global constant to `numpy.typing` denoting whether or not `typing_extensions` is available
Diffstat (limited to 'numpy/typing/_char_codes.py')
-rw-r--r--numpy/typing/_char_codes.py16
1 files changed, 6 insertions, 10 deletions
diff --git a/numpy/typing/_char_codes.py b/numpy/typing/_char_codes.py
index 6b6f7ae88..24d39c62e 100644
--- a/numpy/typing/_char_codes.py
+++ b/numpy/typing/_char_codes.py
@@ -1,18 +1,14 @@
import sys
from typing import Any, TYPE_CHECKING
+from . import _HAS_TYPING_EXTENSIONS
+
if sys.version_info >= (3, 8):
from typing import Literal
- HAVE_LITERAL = True
-else:
- try:
- from typing_extensions import Literal
- except ImportError:
- HAVE_LITERAL = False
- else:
- HAVE_LITERAL = True
-
-if TYPE_CHECKING or HAVE_LITERAL:
+elif _HAS_TYPING_EXTENSIONS:
+ from typing_extensions import Literal
+
+if TYPE_CHECKING or _HAS_TYPING_EXTENSIONS:
_BoolCodes = Literal["?", "=?", "<?", ">?", "bool", "bool_", "bool8"]
_UInt8Codes = Literal["uint8", "u1", "=u1", "<u1", ">u1"]