pydantic-json-patch 0.3.0__tar.gz → 0.4.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pydantic_json_patch-0.3.0 → pydantic_json_patch-0.4.0}/PKG-INFO +10 -1
- {pydantic_json_patch-0.3.0 → pydantic_json_patch-0.4.0}/README.md +9 -0
- {pydantic_json_patch-0.3.0 → pydantic_json_patch-0.4.0}/pyproject.toml +1 -1
- {pydantic_json_patch-0.3.0 → pydantic_json_patch-0.4.0}/src/pydantic_json_patch/models.py +9 -8
- {pydantic_json_patch-0.3.0 → pydantic_json_patch-0.4.0}/src/pydantic_json_patch/__init__.py +0 -0
- {pydantic_json_patch-0.3.0 → pydantic_json_patch-0.4.0}/src/pydantic_json_patch/py.typed +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pydantic_json_patch
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.0
|
|
4
4
|
Summary: Pydantic models for implementing JSON Patch.
|
|
5
5
|
Author: Jonathan Sharpe
|
|
6
6
|
Author-email: Jonathan Sharpe <mail@jonrshar.pe>
|
|
@@ -68,6 +68,15 @@ AddOp(op='add', path='/foo/bar', value=123)
|
|
|
68
68
|
'{"op":"add","path":"/foo/bar","value":123}'
|
|
69
69
|
```
|
|
70
70
|
|
|
71
|
+
The operations that take a value (`AddOp`, `ReplaceOp`, and `TestOp`) are generic, so you can parameterize them with a specific value type:
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
>>> from pydantic_json_patch import ReplaceOp
|
|
75
|
+
>>> op = ReplaceOp[str].create(path="/foo/bar", value="hello")
|
|
76
|
+
>>> op
|
|
77
|
+
ReplaceOp[str](op='replace', path='/foo/bar', value='hello')
|
|
78
|
+
```
|
|
79
|
+
|
|
71
80
|
Additionally, there are two compound models:
|
|
72
81
|
|
|
73
82
|
- `Operation` is the union of all the operators; and
|
|
@@ -36,6 +36,15 @@ AddOp(op='add', path='/foo/bar', value=123)
|
|
|
36
36
|
'{"op":"add","path":"/foo/bar","value":123}'
|
|
37
37
|
```
|
|
38
38
|
|
|
39
|
+
The operations that take a value (`AddOp`, `ReplaceOp`, and `TestOp`) are generic, so you can parameterize them with a specific value type:
|
|
40
|
+
|
|
41
|
+
```python
|
|
42
|
+
>>> from pydantic_json_patch import ReplaceOp
|
|
43
|
+
>>> op = ReplaceOp[str].create(path="/foo/bar", value="hello")
|
|
44
|
+
>>> op
|
|
45
|
+
ReplaceOp[str](op='replace', path='/foo/bar', value='hello')
|
|
46
|
+
```
|
|
47
|
+
|
|
39
48
|
Additionally, there are two compound models:
|
|
40
49
|
|
|
41
50
|
- `Operation` is the union of all the operators; and
|
|
@@ -8,6 +8,7 @@ from pydantic import BaseModel, ConfigDict, Field, ValidationInfo, model_validat
|
|
|
8
8
|
|
|
9
9
|
_JSON_POINTER = re.compile(r"^(?:/(?:[^/~]|~[01])+)*$")
|
|
10
10
|
|
|
11
|
+
T = tx.TypeVar("T", default=tp.Any)
|
|
11
12
|
|
|
12
13
|
# region base models
|
|
13
14
|
|
|
@@ -60,7 +61,7 @@ class _FromOp(_BaseOp):
|
|
|
60
61
|
@classmethod
|
|
61
62
|
def create(
|
|
62
63
|
cls, *, path: str | Sequence[str], from_: str | Sequence[str]
|
|
63
|
-
) -> tx.Self: #
|
|
64
|
+
) -> tx.Self: # ty: ignore[invalid-method-override] -- deliberately narrows **kwargs to named params
|
|
64
65
|
pointer = from_ if isinstance(from_, str) else cls._dump_pointer(from_)
|
|
65
66
|
return super().create(path=path, **{"from": pointer})
|
|
66
67
|
|
|
@@ -85,12 +86,12 @@ class _FromOp(_BaseOp):
|
|
|
85
86
|
return self._load_pointer(self.from_)
|
|
86
87
|
|
|
87
88
|
|
|
88
|
-
class _ValueOp(_BaseOp):
|
|
89
|
+
class _ValueOp(_BaseOp, tp.Generic[T]):
|
|
89
90
|
@classmethod
|
|
90
|
-
def create(cls, *, path: str | Sequence[str], value:
|
|
91
|
+
def create(cls, *, path: str | Sequence[str], value: T) -> tx.Self: # ty: ignore[invalid-method-override] -- deliberately narrows **kwargs to named params
|
|
91
92
|
return super().create(path=path, value=value)
|
|
92
93
|
|
|
93
|
-
value:
|
|
94
|
+
value: T = Field(examples=[42])
|
|
94
95
|
"""The value to use in the operation."""
|
|
95
96
|
|
|
96
97
|
|
|
@@ -99,7 +100,7 @@ class _ValueOp(_BaseOp):
|
|
|
99
100
|
# region public models
|
|
100
101
|
|
|
101
102
|
|
|
102
|
-
class AddOp(_ValueOp):
|
|
103
|
+
class AddOp(_ValueOp[T], tp.Generic[T]):
|
|
103
104
|
op: tp.Literal["add"]
|
|
104
105
|
|
|
105
106
|
|
|
@@ -113,17 +114,17 @@ class MoveOp(_FromOp):
|
|
|
113
114
|
|
|
114
115
|
class RemoveOp(_BaseOp):
|
|
115
116
|
@classmethod
|
|
116
|
-
def create(cls, *, path: str | Sequence[str]) -> tx.Self: #
|
|
117
|
+
def create(cls, *, path: str | Sequence[str]) -> tx.Self: # ty: ignore[invalid-method-override] -- deliberately narrows **kwargs to named params
|
|
117
118
|
return super().create(path=path)
|
|
118
119
|
|
|
119
120
|
op: tp.Literal["remove"]
|
|
120
121
|
|
|
121
122
|
|
|
122
|
-
class ReplaceOp(_ValueOp):
|
|
123
|
+
class ReplaceOp(_ValueOp[T], tp.Generic[T]):
|
|
123
124
|
op: tp.Literal["replace"]
|
|
124
125
|
|
|
125
126
|
|
|
126
|
-
class TestOp(_ValueOp):
|
|
127
|
+
class TestOp(_ValueOp[T], tp.Generic[T]):
|
|
127
128
|
op: tp.Literal["test"]
|
|
128
129
|
|
|
129
130
|
|
|
File without changes
|
|
File without changes
|