From aba840ab8b6f55ebade2bed558c8dfcece5dc858 Mon Sep 17 00:00:00 2001 From: Deepak Cherian Date: Fri, 19 Apr 2024 10:55:17 -0600 Subject: [PATCH] fix typing --- xarray/core/types.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) 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):