Skip to content
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

Add typing_extensions as a required dependency #5911

Merged
merged 8 commits into from
Oct 29, 2021
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ci/requirements/environment-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ dependencies:
- setuptools
- sparse
- toolz
- typing_extensions
- zarr
- pip:
- numbagg
1 change: 1 addition & 0 deletions ci/requirements/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ dependencies:
- setuptools
- sparse
- toolz
- typing_extensions
- zarr
- pip:
- numbagg
1 change: 1 addition & 0 deletions ci/requirements/py37-bare-minimum.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ dependencies:
- numpy=1.17
- pandas=1.0
- setuptools=40.4
- typing_extensions=3̇.7
dcherian marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions ci/requirements/py37-min-all-deps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ dependencies:
- setuptools=40.4
- sparse=0.8
- toolz=0.10
- typing_extensions=3.7
- zarr=2.4
- pip:
- numbagg==0.1
1 change: 1 addition & 0 deletions ci/requirements/py38-all-but-dask.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ dependencies:
- setuptools
- sparse
- toolz
- typing_extensions
- zarr
- pip:
- numbagg
1 change: 1 addition & 0 deletions doc/getting-started-guide/installing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Required dependencies

- Python (3.7 or later)
- setuptools (40.4 or later)
- ``typing_extensions`` (3.7 or later)
- `numpy <http://www.numpy.org/>`__ (1.17 or later)
- `pandas <http://pandas.pydata.org/>`__ (1.0 or later)

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
numpy >= 1.17
pandas >= 1.0
setuptools >= 40.4
typing-extensions >= 3.10
typing-extensions >= 3.7
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ python_requires = >=3.7
install_requires =
numpy >= 1.17
pandas >= 1.0
typing_extensions >= 3.7
setuptools >= 40.4 # For pkg_resources

[options.extras_require]
Expand Down
11 changes: 2 additions & 9 deletions xarray/core/npcompat.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,10 @@
# fall back for numpy < 1.20, ArrayLike adapted from numpy.typing._array_like
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
from typing_extensions import Protocol

if TYPE_CHECKING or HAVE_PROTOCOL:
if TYPE_CHECKING:

class _SupportsArray(Protocol):
def __array__(self) -> np.ndarray:
Expand Down
83 changes: 24 additions & 59 deletions xarray/core/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,70 +6,35 @@
# TODO: Remove this check once python 3.7 is not supported:
if sys.version_info >= (3, 8):
from typing import TYPE_CHECKING, Literal, TypedDict, Union
else:
from typing import TYPE_CHECKING, Union

if TYPE_CHECKING:
try:
from matplotlib.colors import Colormap
except ImportError:
Colormap = str

class T_Options(TypedDict):
arithmetic_join: Literal["inner", "outer", "left", "right", "exact"]
cmap_divergent: Union[str, "Colormap"]
cmap_sequential: Union[str, "Colormap"]
display_max_rows: int
display_style: Literal["text", "html"]
display_width: int
display_expand_attrs: Literal["default", True, False]
display_expand_coords: Literal["default", True, False]
display_expand_data_vars: Literal["default", True, False]
display_expand_data: Literal["default", True, False]
enable_cftimeindex: bool
file_cache_maxsize: int
keep_attrs: Literal["default", True, False]
warn_for_unclosed_files: bool
use_bottleneck: bool
from typing_extensions import Literal, TypedDict


else:
# See GH5624, this is a convoluted way to allow type-checking to use
# `TypedDict` and `Literal` without requiring typing_extensions as a
# required dependency to _run_ the code (it is required to type-check).
if TYPE_CHECKING:
try:
from typing import TYPE_CHECKING, Union

from typing_extensions import Literal, TypedDict

if TYPE_CHECKING:
try:
from matplotlib.colors import Colormap
except ImportError:
Colormap = str

class T_Options(TypedDict):
arithmetic_join: Literal["inner", "outer", "left", "right", "exact"]
cmap_divergent: Union[str, "Colormap"]
cmap_sequential: Union[str, "Colormap"]
display_max_rows: int
display_style: Literal["text", "html"]
display_width: int
display_expand_attrs: Literal["default", True, False]
display_expand_coords: Literal["default", True, False]
display_expand_data_vars: Literal["default", True, False]
display_expand_data: Literal["default", True, False]
enable_cftimeindex: bool
file_cache_maxsize: int
keep_attrs: Literal["default", True, False]
warn_for_unclosed_files: bool
use_bottleneck: bool

from matplotlib.colors import Colormap
except ImportError:
from typing import TYPE_CHECKING, Any, Dict, Hashable

if TYPE_CHECKING:
raise
else:
T_Options = Dict[Hashable, Any]
Colormap = str


class T_Options(TypedDict):
arithmetic_join: Literal["inner", "outer", "left", "right", "exact"]
cmap_divergent: Union[str, "Colormap"]
cmap_sequential: Union[str, "Colormap"]
display_max_rows: int
display_style: Literal["text", "html"]
display_width: int
display_expand_attrs: Literal["default", True, False]
display_expand_coords: Literal["default", True, False]
display_expand_data_vars: Literal["default", True, False]
display_expand_data: Literal["default", True, False]
enable_cftimeindex: bool
file_cache_maxsize: int
keep_attrs: Literal["default", True, False]
warn_for_unclosed_files: bool
use_bottleneck: bool


OPTIONS: T_Options = {
Expand Down