Skip to content

Commit f54cbfa

Browse files
committed
Fix is_generic
1 parent a8c1898 commit f54cbfa

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/cattrs/_compat.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,8 +403,10 @@ def is_generic(type) -> bool:
403403
"""Whether `type` is a generic type."""
404404
# Inheriting from protocol will inject `Generic` into the MRO
405405
# without `__orig_bases__`.
406-
return isinstance(type, (_GenericAlias, GenericAlias)) or (
407-
is_subclass(type, Generic) and hasattr(type, "__orig_bases__")
406+
return (
407+
isinstance(type, (_GenericAlias, GenericAlias))
408+
or (is_subclass(type, Generic) and hasattr(type, "__orig_bases__"))
409+
or type.__class__ is Union # On 3.14, unions are no longer typing._GenericAlias
408410
)
409411

410412

src/cattrs/_generics.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
from collections.abc import Mapping
2-
from typing import Any
2+
from typing import Any, get_args
33

44
from attrs import NOTHING
55
from typing_extensions import Self
66

7-
from ._compat import copy_with, get_args, is_annotated, is_generic
7+
from ._compat import copy_with, is_annotated, is_generic
88

99

1010
def deep_copy_with(t, mapping: Mapping[str, Any], self_is=NOTHING):

0 commit comments

Comments
 (0)