Skip to content

Commit 057cb55

Browse files
committed
fix: put UNION_TYPES back in the ~public API
1 parent a827216 commit 057cb55

File tree

6 files changed

+15
-17
lines changed

6 files changed

+15
-17
lines changed

scim2_models/base.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from scim2_models.annotations import Required
2424
from scim2_models.annotations import Returned
2525
from scim2_models.context import Context
26-
from scim2_models.utils import _UNION_TYPES
26+
from scim2_models.utils import UNION_TYPES
2727
from scim2_models.utils import _find_field_name
2828
from scim2_models.utils import _normalize_attribute_name
2929
from scim2_models.utils import _to_camel
@@ -77,7 +77,7 @@ def get_field_root_type(cls, attribute_name: str) -> Optional[type]:
7777
attribute_type = cls.model_fields[attribute_name].annotation
7878

7979
# extract 'x' from 'Optional[x]'
80-
if get_origin(attribute_type) in _UNION_TYPES:
80+
if get_origin(attribute_type) in UNION_TYPES:
8181
attribute_type = get_args(attribute_type)[0]
8282

8383
# extract 'x' from 'List[x]'
@@ -93,7 +93,7 @@ def get_field_multiplicity(cls, attribute_name: str) -> bool:
9393
attribute_type = cls.model_fields[attribute_name].annotation
9494

9595
# extract 'x' from 'Optional[x]'
96-
if get_origin(attribute_type) in _UNION_TYPES:
96+
if get_origin(attribute_type) in UNION_TYPES:
9797
attribute_type = get_args(attribute_type)[0]
9898

9999
origin = get_origin(attribute_type)
@@ -104,7 +104,7 @@ def get_field_multiplicity(cls, attribute_name: str) -> bool:
104104
def check_request_attributes_mutability(
105105
cls, value: Any, info: ValidationInfo
106106
) -> Any:
107-
"""Check and fix that the field mutability is expected according to the requests validation context, as defined in :rfc:`RFC7643 §7 <7653#section-7>`."""
107+
"""Check and fix that the field mutability is expected according to the requests validation context, as defined in :rfc:`RFC7643 §7 <7643#section-7>`."""
108108
if (
109109
not info.context
110110
or not info.field_name
@@ -147,7 +147,7 @@ def normalize_attribute_names(
147147
) -> Self:
148148
"""Normalize payload attribute names.
149149
150-
:rfc:`RFC7643 §2.1 <7653#section-2.1>` indicate that attribute
150+
:rfc:`RFC7643 §2.1 <7643#section-2.1>` indicate that attribute
151151
names should be case-insensitive. Any attribute name is
152152
transformed in lowercase so any case is handled the same way.
153153
"""
@@ -199,7 +199,7 @@ def normalize_value(
199199
def check_response_attributes_returnability(
200200
cls, value: Any, handler: ValidatorFunctionWrapHandler, info: ValidationInfo
201201
) -> Self:
202-
"""Check that the fields returnability is expected according to the responses validation context, as defined in :rfc:`RFC7643 §7 <7653#section-7>`."""
202+
"""Check that the fields returnability is expected according to the responses validation context, as defined in :rfc:`RFC7643 §7 <7643#section-7>`."""
203203
obj = handler(value)
204204
assert isinstance(obj, cls)
205205

scim2_models/context.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class Context(Enum):
7878
7979
- When used for serialization, it will not dump attributes annotated with :attr:`~scim2_models.Mutability.read_only`.
8080
- When used for validation, it will ignore attributes annotated with :attr:`scim2_models.Mutability.read_only` and raise a :class:`~pydantic.ValidationError`:
81-
- when finding attributes annotated with :attr:`~scim2_models.Mutability.immutable` different than :paramref:`~scim2_models.BaseModel.model_validate.original`:
81+
- when finding attributes annotated with :attr:`~scim2_models.Mutability.immutable` different than the ``original`` parameter passed to :meth:`~scim2_models.BaseModel.model_validate`;
8282
- when attributes annotated with :attr:`Required.true <scim2_models.Required.true>` are missing on null.
8383
"""
8484

scim2_models/messages/message.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
from ..base import BaseModel
1616
from ..scim_object import ScimObject
17-
from ..utils import _UNION_TYPES
17+
from ..utils import UNION_TYPES
1818

1919

2020
class Message(ScimObject):
@@ -69,7 +69,7 @@ def _create_tagged_resource_union(resource_union: Any) -> Any:
6969
:param resource_union: Union type of SCIM resources
7070
:return: Annotated discriminated union or original type
7171
"""
72-
if get_origin(resource_union) not in _UNION_TYPES:
72+
if get_origin(resource_union) not in UNION_TYPES:
7373
return resource_union
7474

7575
resource_types = get_args(resource_union)

scim2_models/reference.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from pydantic_core import core_schema
1010
from typing_extensions import NewType
1111

12-
from .utils import _UNION_TYPES
12+
from .utils import UNION_TYPES
1313

1414
ReferenceTypes = TypeVar("ReferenceTypes")
1515

@@ -67,9 +67,7 @@ def get_types(cls, type_annotation: Any) -> list[str]:
6767
"""
6868
first_arg = get_args(type_annotation)[0]
6969
types = (
70-
get_args(first_arg)
71-
if get_origin(first_arg) in _UNION_TYPES
72-
else [first_arg]
70+
get_args(first_arg) if get_origin(first_arg) in UNION_TYPES else [first_arg]
7371
)
7472

7573
def serialize_ref_type(ref_type: Any) -> str:

scim2_models/resources/resource.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from ..reference import Reference
3030
from ..scim_object import ScimObject
3131
from ..urn import _validate_attribute_urn
32-
from ..utils import _UNION_TYPES
32+
from ..utils import UNION_TYPES
3333
from ..utils import _normalize_attribute_name
3434

3535
if TYPE_CHECKING:
@@ -153,7 +153,7 @@ def __class_getitem__(cls, item: Any) -> type["Resource"]:
153153
if hasattr(cls, "__scim_extension_metadata__"):
154154
return cls
155155

156-
extensions = get_args(item) if get_origin(item) in _UNION_TYPES else [item]
156+
extensions = get_args(item) if get_origin(item) in UNION_TYPES else [item]
157157

158158
# Skip TypeVar parameters and Any (used for generic class definitions)
159159
valid_extensions = [

scim2_models/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
try:
1414
from types import UnionType
1515

16-
_UNION_TYPES = [Union, UnionType]
16+
UNION_TYPES = [Union, UnionType]
1717
except ImportError:
1818
# Python 3.9 has no UnionType
19-
_UNION_TYPES = [Union]
19+
UNION_TYPES = [Union]
2020

2121

2222
def _int_to_str(status: Optional[int]) -> Optional[str]:

0 commit comments

Comments
 (0)