diff --git a/xarray/core/npcompat.py b/xarray/core/npcompat.py index 1018332df29..40576d1fc37 100644 --- a/xarray/core/npcompat.py +++ b/xarray/core/npcompat.py @@ -75,10 +75,12 @@ def moveaxis(a, source, destination): return result -# Type annotations stubs. See also / to be replaced by: -# https://github.com/numpy/numpy/issues/7370 -# https://github.com/numpy/numpy-stubs/ -DTypeLike = Union[np.dtype, str] +# Type annotations stubs. +try: + from numpy.typing import DTypeLike +except ImportError: + # fall back for numpy < 1.20 + DTypeLike = Union[np.dtype, str] # from dask/array/utils.py