Skip to content

Commit 3a80714

Browse files
committed
Conditionally import _UnionGenericAlias
1 parent b1ea021 commit 3a80714

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

src/cattrs/_compat.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
_AnnotatedAlias,
3030
_GenericAlias,
3131
_SpecialGenericAlias,
32-
_UnionGenericAlias,
3332
get_args,
3433
get_origin,
3534
get_type_hints,
@@ -256,7 +255,22 @@ def is_tuple(type):
256255
)
257256

258257

259-
if sys.version_info >= (3, 10):
258+
if sys.version_info >= (3, 14):
259+
260+
def is_union_type(obj):
261+
from types import UnionType # noqa: PLC0415
262+
263+
return obj is Union or isinstance(obj, UnionType)
264+
265+
def get_newtype_base(typ: Any) -> Optional[type]:
266+
if typ is NewType or isinstance(typ, NewType):
267+
return typ.__supertype__
268+
return None
269+
270+
from typing import NotRequired, Required
271+
272+
elif sys.version_info >= (3, 10):
273+
from typing import _UnionGenericAlias
260274

261275
def is_union_type(obj):
262276
from types import UnionType # noqa: PLC0415
@@ -279,6 +293,8 @@ def get_newtype_base(typ: Any) -> Optional[type]:
279293

280294
else:
281295
# 3.9
296+
from typing import _UnionGenericAlias
297+
282298
from typing_extensions import NotRequired, Required
283299

284300
def is_union_type(obj):

0 commit comments

Comments
 (0)