Skip to content

Commit 2e2807c

Browse files
committed
feat: allow Path objects in Pydantic validation methods
1 parent f27a83a commit 2e2807c

File tree

4 files changed

+24
-7
lines changed

4 files changed

+24
-7
lines changed

doc/changelog.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
Changelog
22
=========
33

4+
[0.6.1] - 2026-01-25
5+
--------------------
6+
7+
Added
8+
^^^^^
9+
- Allow ``Path`` objects in Pydantic validation methods.
10+
411
[0.6.0] - 2026-01-25
512
--------------------
613

scim2_models/path.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,9 @@ def validate_path(value: Any) -> "Path[Any]":
129129
serialization=core_schema.plain_serializer_function_ser_schema(str),
130130
)
131131

132-
def __init__(self, path: str):
132+
def __init__(self, path: "str | Path[Any]"):
133+
if isinstance(path, Path):
134+
path = str(path)
133135
self.check_syntax(path)
134136
self.data = path
135137

scim2_models/resources/resource.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -386,8 +386,8 @@ def from_schema(cls, schema: "Schema") -> type["Resource[Any]"]:
386386
def _prepare_model_dump(
387387
self,
388388
scim_ctx: Context | None = Context.DEFAULT,
389-
attributes: list[str] | None = None,
390-
excluded_attributes: list[str] | None = None,
389+
attributes: list[str | Path[Any]] | None = None,
390+
excluded_attributes: list[str | Path[Any]] | None = None,
391391
**kwargs: Any,
392392
) -> dict[str, Any]:
393393
kwargs = super()._prepare_model_dump(scim_ctx, **kwargs)
@@ -410,8 +410,8 @@ def model_dump(
410410
self,
411411
*args: Any,
412412
scim_ctx: Context | None = Context.DEFAULT,
413-
attributes: list[str] | None = None,
414-
excluded_attributes: list[str] | None = None,
413+
attributes: list[str | Path[Any]] | None = None,
414+
excluded_attributes: list[str | Path[Any]] | None = None,
415415
**kwargs: Any,
416416
) -> dict[str, Any]:
417417
"""Create a model representation that can be included in SCIM messages by using Pydantic :code:`BaseModel.model_dump`.
@@ -436,8 +436,8 @@ def model_dump_json(
436436
self,
437437
*args: Any,
438438
scim_ctx: Context | None = Context.DEFAULT,
439-
attributes: list[str] | None = None,
440-
excluded_attributes: list[str] | None = None,
439+
attributes: list[str | Path[Any]] | None = None,
440+
excluded_attributes: list[str | Path[Any]] | None = None,
441441
**kwargs: Any,
442442
) -> str:
443443
"""Create a JSON model representation that can be included in SCIM messages by using Pydantic :code:`BaseModel.model_dump_json`.

tests/test_path.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1417,3 +1417,11 @@ def test_iter_paths_filter_skips_non_matching_subattributes():
14171417

14181418
assert "members" in path_strings
14191419
assert len(paths_with_filter) < len(paths_no_filter)
1420+
1421+
1422+
def test_path_init_with_path_object():
1423+
"""Path can be initialized with another Path object."""
1424+
original = Path("userName")
1425+
copy = Path(original)
1426+
assert str(copy) == "userName"
1427+
assert copy.data == original.data

0 commit comments

Comments
 (0)