Skip to content
forked from pydata/xarray

Commit bcb96ce

Browse files
authored
Add typing_extensions as a required dependency (pydata#5911)
1 parent ba00852 commit bcb96ce

File tree

10 files changed

+34
-69
lines changed

10 files changed

+34
-69
lines changed

ci/requirements/environment-windows.yml

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ dependencies:
3939
- setuptools
4040
- sparse
4141
- toolz
42+
- typing_extensions
4243
- zarr
4344
- pip:
4445
- numbagg

ci/requirements/environment.yml

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ dependencies:
4343
- setuptools
4444
- sparse
4545
- toolz
46+
- typing_extensions
4647
- zarr
4748
- pip:
4849
- numbagg

ci/requirements/py37-bare-minimum.yml

+1
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ dependencies:
1313
- numpy=1.17
1414
- pandas=1.0
1515
- setuptools=40.4
16+
- typing_extensions=3.7

ci/requirements/py37-min-all-deps.yml

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ dependencies:
4747
- setuptools=40.4
4848
- sparse=0.8
4949
- toolz=0.10
50+
- typing_extensions=3.7
5051
- zarr=2.4
5152
- pip:
5253
- numbagg==0.1

ci/requirements/py38-all-but-dask.yml

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ dependencies:
3939
- setuptools
4040
- sparse
4141
- toolz
42+
- typing_extensions
4243
- zarr
4344
- pip:
4445
- numbagg

doc/getting-started-guide/installing.rst

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Required dependencies
88

99
- Python (3.7 or later)
1010
- setuptools (40.4 or later)
11+
- ``typing_extensions`` (3.7 or later)
1112
- `numpy <http://www.numpy.org/>`__ (1.17 or later)
1213
- `pandas <http://pandas.pydata.org/>`__ (1.0 or later)
1314

requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
numpy >= 1.17
66
pandas >= 1.0
77
setuptools >= 40.4
8-
typing-extensions >= 3.10
8+
typing-extensions >= 3.7

setup.cfg

+1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ python_requires = >=3.7
7878
install_requires =
7979
numpy >= 1.17
8080
pandas >= 1.0
81+
typing_extensions >= 3.7
8182
setuptools >= 40.4 # For pkg_resources
8283

8384
[options.extras_require]

xarray/core/npcompat.py

+2-9
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,10 @@
4141
# fall back for numpy < 1.20, ArrayLike adapted from numpy.typing._array_like
4242
if sys.version_info >= (3, 8):
4343
from typing import Protocol
44-
45-
HAVE_PROTOCOL = True
4644
else:
47-
try:
48-
from typing_extensions import Protocol
49-
except ImportError:
50-
HAVE_PROTOCOL = False
51-
else:
52-
HAVE_PROTOCOL = True
45+
from typing_extensions import Protocol
5346

54-
if TYPE_CHECKING or HAVE_PROTOCOL:
47+
if TYPE_CHECKING:
5548

5649
class _SupportsArray(Protocol):
5750
def __array__(self) -> np.ndarray:

xarray/core/options.py

+24-59
Original file line numberDiff line numberDiff line change
@@ -6,70 +6,35 @@
66
# TODO: Remove this check once python 3.7 is not supported:
77
if sys.version_info >= (3, 8):
88
from typing import TYPE_CHECKING, Literal, TypedDict, Union
9+
else:
10+
from typing import TYPE_CHECKING, Union
911

10-
if TYPE_CHECKING:
11-
try:
12-
from matplotlib.colors import Colormap
13-
except ImportError:
14-
Colormap = str
15-
16-
class T_Options(TypedDict):
17-
arithmetic_join: Literal["inner", "outer", "left", "right", "exact"]
18-
cmap_divergent: Union[str, "Colormap"]
19-
cmap_sequential: Union[str, "Colormap"]
20-
display_max_rows: int
21-
display_style: Literal["text", "html"]
22-
display_width: int
23-
display_expand_attrs: Literal["default", True, False]
24-
display_expand_coords: Literal["default", True, False]
25-
display_expand_data_vars: Literal["default", True, False]
26-
display_expand_data: Literal["default", True, False]
27-
enable_cftimeindex: bool
28-
file_cache_maxsize: int
29-
keep_attrs: Literal["default", True, False]
30-
warn_for_unclosed_files: bool
31-
use_bottleneck: bool
12+
from typing_extensions import Literal, TypedDict
3213

3314

34-
else:
35-
# See GH5624, this is a convoluted way to allow type-checking to use
36-
# `TypedDict` and `Literal` without requiring typing_extensions as a
37-
# required dependency to _run_ the code (it is required to type-check).
15+
if TYPE_CHECKING:
3816
try:
39-
from typing import TYPE_CHECKING, Union
40-
41-
from typing_extensions import Literal, TypedDict
42-
43-
if TYPE_CHECKING:
44-
try:
45-
from matplotlib.colors import Colormap
46-
except ImportError:
47-
Colormap = str
48-
49-
class T_Options(TypedDict):
50-
arithmetic_join: Literal["inner", "outer", "left", "right", "exact"]
51-
cmap_divergent: Union[str, "Colormap"]
52-
cmap_sequential: Union[str, "Colormap"]
53-
display_max_rows: int
54-
display_style: Literal["text", "html"]
55-
display_width: int
56-
display_expand_attrs: Literal["default", True, False]
57-
display_expand_coords: Literal["default", True, False]
58-
display_expand_data_vars: Literal["default", True, False]
59-
display_expand_data: Literal["default", True, False]
60-
enable_cftimeindex: bool
61-
file_cache_maxsize: int
62-
keep_attrs: Literal["default", True, False]
63-
warn_for_unclosed_files: bool
64-
use_bottleneck: bool
65-
17+
from matplotlib.colors import Colormap
6618
except ImportError:
67-
from typing import TYPE_CHECKING, Any, Dict, Hashable
68-
69-
if TYPE_CHECKING:
70-
raise
71-
else:
72-
T_Options = Dict[Hashable, Any]
19+
Colormap = str
20+
21+
22+
class T_Options(TypedDict):
23+
arithmetic_join: Literal["inner", "outer", "left", "right", "exact"]
24+
cmap_divergent: Union[str, "Colormap"]
25+
cmap_sequential: Union[str, "Colormap"]
26+
display_max_rows: int
27+
display_style: Literal["text", "html"]
28+
display_width: int
29+
display_expand_attrs: Literal["default", True, False]
30+
display_expand_coords: Literal["default", True, False]
31+
display_expand_data_vars: Literal["default", True, False]
32+
display_expand_data: Literal["default", True, False]
33+
enable_cftimeindex: bool
34+
file_cache_maxsize: int
35+
keep_attrs: Literal["default", True, False]
36+
warn_for_unclosed_files: bool
37+
use_bottleneck: bool
7338

7439

7540
OPTIONS: T_Options = {

0 commit comments

Comments
 (0)