Skip to content

Commit d3cb64e

Browse files
committed
fix: BaseModel.get_field_root_type supports UnionType
1 parent 5029f40 commit d3cb64e

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

doc/changelog.rst

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Added
88
^^^^^
99
- Python 3.13 support.
1010
- Proper Base64 serialization. #31
11+
- :meth:`~BaseModel.get_field_root_type` supports :data:`~typing.UnionType`.
1112

1213
Changed
1314
^^^^^^^

scim2_models/base.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from enum import Enum
33
from enum import auto
44
from inspect import isclass
5+
from types import UnionType
56
from typing import Annotated
67
from typing import Any
78
from typing import Generic
@@ -437,7 +438,7 @@ def get_field_root_type(cls, attribute_name: str) -> type:
437438
attribute_type = cls.model_fields[attribute_name].annotation
438439

439440
# extract 'x' from 'Optional[x]'
440-
if get_origin(attribute_type) is Union:
441+
if get_origin(attribute_type) in (Union, UnionType):
441442
attribute_type = get_args(attribute_type)[0]
442443

443444
# extract 'x' from 'List[x]'

0 commit comments

Comments
 (0)