diff --git a/xarray/core/types.py b/xarray/core/types.py index a5978405db4..97dcf9e1065 100644 --- a/xarray/core/types.py +++ b/xarray/core/types.py @@ -88,14 +88,15 @@ else: DTypeLikeSave: Any = None -DatetimeLikeNoCFTime = Union[pd.Timestamp, datetime.datetime, np.datetime64] +# https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases try: from cftime import datetime as CFTimeDatetime - - DatetimeLike = Union[DatetimeLikeNoCFTime, CFTimeDatetime] except ImportError: - CFTimeDatetime = Any - DatetimeLike = DatetimeLikeNoCFTime + CFTimeDatetime = np.datetime64 + +DatetimeLike: TypeAlias = ( + pd.Timestamp | datetime.datetime | np.datetime64 | CFTimeDatetime +) class Alignable(Protocol):