Skip to content

Commit

Permalink
Make typing-extensions optional
Browse files Browse the repository at this point in the history
Fixes pydataGH-5495

Type checking may be a little worse if typing-extensions are not
installed, but I don't think it's worth the trouble of adding another
hard dependency just for one use for TypeGuard.
  • Loading branch information
shoyer committed Jul 19, 2021
1 parent 64ed93e commit 8607b2e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ classifiers =
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Topic :: Scientific/Engineering

[options]
Expand All @@ -78,7 +79,6 @@ install_requires =
numpy >= 1.17
pandas >= 1.0
setuptools >= 40.4 # For pkg_resources
typing-extensions >= 3.10 # Backported type hints

[options.extras_require]
io =
Expand Down
14 changes: 9 additions & 5 deletions xarray/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,14 @@
import numpy as np
import pandas as pd

if sys.version_info >= (3, 10):
from typing import TypeGuard
else:
from typing_extensions import TypeGuard
try:
if sys.version_info >= (3, 10):
from typing import TypeGuard
else:
from typing_extensions import TypeGuard
TypeGuardHashable = TypeGuard[Hashable]
except ImportError:
TypeGuardHashable = bool


K = TypeVar("K")
Expand Down Expand Up @@ -297,7 +301,7 @@ def either_dict_or_kwargs(
return pos_kwargs


def is_scalar(value: Any, include_0d: bool = True) -> TypeGuard[Hashable]:
def is_scalar(value: Any, include_0d: bool = True) -> TypeGuardHashable:
"""Whether to treat a value as a scalar.
Any non-iterable, string, or 0-D array
Expand Down

0 comments on commit 8607b2e

Please sign in to comment.