jsonpatch 1.40__py3-none-any.whl → 1.41__py3-none-any.whl

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: jsonpatch
3
- Version: 1.40
3
+ Version: 1.41
4
4
  Summary: Apply JSON-Patches (RFC 6902)
5
5
  Home-page: https://github.com/stefankoegl/python-json-patch
6
6
  Author: Stefan Kögl
@@ -28,11 +28,12 @@ Classifier: Programming Language :: Python :: Implementation :: CPython
28
28
  Classifier: Programming Language :: Python :: Implementation :: PyPy
29
29
  Classifier: Topic :: Software Development :: Libraries
30
30
  Classifier: Topic :: Utilities
31
+ Classifier: Typing :: Typed
31
32
  Requires-Python: >=3.10
32
33
  Description-Content-Type: text/markdown
33
34
  License-File: LICENSE
34
35
  License-File: AUTHORS
35
- Requires-Dist: jsonpointer>=3.2
36
+ Requires-Dist: jsonpointer>=3.8
36
37
  Dynamic: author
37
38
  Dynamic: author-email
38
39
  Dynamic: classifier
@@ -69,6 +70,20 @@ See source code for examples
69
70
  * CI: https://github.com/stefankoegl/python-json-patch/actions
70
71
  * Coveralls: https://coveralls.io/github/stefankoegl/python-json-patch
71
72
 
73
+ Type hints
74
+ ----------
75
+ jsonpatch ships type stubs (in the `jsonpatch-stubs` directory, as
76
+ jsonpatch.py is a single-file module), so type checkers such as mypy and
77
+ pyright work with it without further setup. JSON documents are typed as `Any`.
78
+
79
+ When changing the public API of jsonpatch.py, update
80
+ `jsonpatch-stubs/__init__.pyi` as well. These check that both agree, and that
81
+ typical usage in `typetests/usage.py` type-checks:
82
+
83
+ pip install mypy .
84
+ python -m mypy.stubtest --mypy-config-file pyproject.toml jsonpatch
85
+ cd typetests && mypy --config-file ../pyproject.toml usage.py
86
+
72
87
  Running external tests
73
88
  ----------------------
74
89
  To run external tests (such as those from https://github.com/json-patch/json-patch-tests) use ext_tests.py
@@ -0,0 +1,10 @@
1
+ jsonpatch.py,sha256=i0UN_UBxpx9ClyplHpbEEhVpHC-ckzcwqlAsPutxD28,47675
2
+ jsonpatch_cli.py,sha256=ooxDB62_Vcx6ryCbyMHItkNgmZjp73ZOyxgV1IAcdVI,6274
3
+ jsonpatch-1.41.dist-info/licenses/AUTHORS,sha256=hOtEnBGbfDegKjzMDEl5vuVJyczbI2PlYE2ho4LjGNQ,140
4
+ jsonpatch-1.41.dist-info/licenses/LICENSE,sha256=Q5PrZzP6HjZ_QXabOC9PG-e_Da6x4kPtkrP12Lr9I28,1481
5
+ jsonpatch-stubs/__init__.pyi,sha256=puuW3LKHkYNSMyGQ_0XqfDwqLjdHbSUTJU79gpPZy54,5215
6
+ jsonpatch-1.41.dist-info/METADATA,sha256=je3-rYA4OmtMG6NM7sDfYCSU3MSttqM9CmKJ4ugSFEo,4287
7
+ jsonpatch-1.41.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
8
+ jsonpatch-1.41.dist-info/entry_points.txt,sha256=aY9ormBVRZHHDaAeMcdqTBwZ-ax7GvBTSQ33I75xtZM,98
9
+ jsonpatch-1.41.dist-info/top_level.txt,sha256=AGmziZtf5TSFAtbhYlhDGjQg1POmwzF9HwLdbzPkoio,40
10
+ jsonpatch-1.41.dist-info/RECORD,,
@@ -1,2 +1,3 @@
1
1
  jsonpatch
2
+ jsonpatch-stubs
2
3
  jsonpatch_cli
@@ -0,0 +1,146 @@
1
+ # Type stubs for jsonpatch.
2
+ #
3
+ # jsonpatch is a single-file module, and PEP 561 has no py.typed marker for
4
+ # those, so its types are shipped as this stub-only package in the same
5
+ # distribution. Keep it in sync with jsonpatch.py; CI runs mypy's stubtest to
6
+ # check that both agree.
7
+ #
8
+ # JSON documents are typed as Any: they can be any JSON value, and the module
9
+ # also accepts arbitrary Mapping / Sequence types, which a recursive JSON type
10
+ # would reject.
11
+
12
+ from collections.abc import Callable, Iterable, Iterator, Mapping, Sequence
13
+ from typing import Any, ClassVar
14
+
15
+ # Re-exported, as jsonpatch.py imports them and users rely on that, e.g. to
16
+ # catch jsonpatch.JsonPointerException. stubtest does not check these, as
17
+ # they are defined in another module.
18
+ from jsonpointer import JsonPointer as JsonPointer
19
+ from jsonpointer import JsonPointerException as JsonPointerException
20
+ from typing_extensions import Self
21
+
22
+ __author__: str
23
+ __version__: str
24
+ __website__: str
25
+ __license__: str
26
+
27
+ # A single patch operation, e.g. {'op': 'add', 'path': '/a', 'value': 1}
28
+ _Operation = Mapping[str, Any]
29
+
30
+ class JsonPatchException(Exception):
31
+ # The failing operation: a PatchOperation, or the raw operation object if
32
+ # none could be constructed from it, or None.
33
+ op: Any
34
+ def __init__(self, *args: object, op: Any = None) -> None: ...
35
+
36
+ class InvalidJsonPatch(JsonPatchException): ...
37
+ class JsonPatchConflict(JsonPatchException): ...
38
+ class JsonPatchTestFailed(JsonPatchException, AssertionError): ...
39
+
40
+ def multidict(ordered_pairs: Iterable[tuple[str, Any]]) -> dict[str, Any]: ...
41
+ def apply_patch(
42
+ doc: Any,
43
+ patch: str | bytes | Iterable[_Operation],
44
+ in_place: bool = False,
45
+ pointer_cls: type[JsonPointer] = ...,
46
+ ) -> Any: ...
47
+ def make_patch(
48
+ src: Any,
49
+ dst: Any,
50
+ pointer_cls: type[JsonPointer] = ...,
51
+ generate_test_ops: bool = False,
52
+ ) -> JsonPatch: ...
53
+
54
+ class PatchOperation:
55
+ pointer_cls: type[JsonPointer]
56
+ location: str
57
+ pointer: JsonPointer
58
+ operation: _Operation
59
+ def __init__(self, operation: _Operation, pointer_cls: type[JsonPointer] = ...) -> None: ...
60
+ def apply(self, obj: Any) -> Any: ...
61
+ def __hash__(self) -> int: ...
62
+ def __eq__(self, other: object) -> bool: ...
63
+ def __ne__(self, other: object) -> bool: ...
64
+ @property
65
+ def path(self) -> str: ...
66
+ @property
67
+ def key(self) -> int | str: ...
68
+ @key.setter
69
+ def key(self, value: int | str) -> None: ...
70
+ def get_part(self, index: int) -> int | str: ...
71
+ def set_part(self, index: int, value: int | str) -> None: ...
72
+
73
+ class RemoveOperation(PatchOperation): ...
74
+ class AddOperation(PatchOperation): ...
75
+ class ReplaceOperation(PatchOperation): ...
76
+
77
+ class MoveOperation(PatchOperation):
78
+ @property
79
+ def from_path(self) -> str: ...
80
+ @property
81
+ def from_key(self) -> int | str: ...
82
+ @from_key.setter
83
+ def from_key(self, value: int | str) -> None: ...
84
+ def get_from_part(self, index: int) -> int | str: ...
85
+ def set_from_part(self, index: int, value: int | str) -> None: ...
86
+
87
+ class TestOperation(PatchOperation): ...
88
+ class CopyOperation(PatchOperation): ...
89
+
90
+ class JsonPatch:
91
+ json_dumper: ClassVar[Callable[..., str]]
92
+ json_loader: ClassVar[Callable[..., Any]]
93
+ operations: ClassVar[Mapping[str, type[PatchOperation]]]
94
+ pointer_cls: type[JsonPointer]
95
+ patch: Sequence[_Operation]
96
+ def __init__(self, patch: Iterable[_Operation], pointer_cls: type[JsonPointer] = ...) -> None: ...
97
+ def __bool__(self) -> bool: ...
98
+ def __iter__(self) -> Iterator[_Operation]: ...
99
+ def __hash__(self) -> int: ...
100
+ def __eq__(self, other: object) -> bool: ...
101
+ def __ne__(self, other: object) -> bool: ...
102
+ __nonzero__ = __bool__
103
+ @classmethod
104
+ def from_string(
105
+ cls,
106
+ patch_str: str | bytes | bytearray,
107
+ loads: Callable[[Any], Any] | None = None,
108
+ pointer_cls: type[JsonPointer] = ...,
109
+ ) -> Self: ...
110
+ @classmethod
111
+ def from_diff(
112
+ cls,
113
+ src: Any,
114
+ dst: Any,
115
+ optimization: bool = True,
116
+ dumps: Callable[[Any], str] | None = None,
117
+ pointer_cls: type[JsonPointer] = ...,
118
+ generate_test_ops: bool = False,
119
+ ) -> Self: ...
120
+ def to_string(self, dumps: Callable[[Any], str] | None = None) -> str: ...
121
+ def apply(self, obj: Any, in_place: bool = False) -> Any: ...
122
+
123
+ # Computes the operations for JsonPatch.from_diff; mostly an implementation
124
+ # detail, so its internal methods are typed loosely.
125
+ class DiffBuilder:
126
+ dumps: Callable[[Any], str]
127
+ pointer_cls: type[JsonPointer]
128
+ optimization: bool
129
+ generate_test_ops: bool
130
+ src_doc: Any
131
+ dst_doc: Any
132
+ def __init__(
133
+ self,
134
+ src_doc: Any,
135
+ dst_doc: Any,
136
+ dumps: Callable[[Any], str] = ...,
137
+ pointer_cls: type[JsonPointer] = ...,
138
+ optimization: bool = True,
139
+ generate_test_ops: bool = False,
140
+ ) -> None: ...
141
+ def store_index(self, value: Any, index: Any, st: int) -> None: ...
142
+ def take_index(self, value: Any, st: int) -> Any: ...
143
+ def insert(self, op: Any) -> Any: ...
144
+ def remove(self, index: Any) -> None: ...
145
+ def __iter__(self) -> Iterator[Any]: ...
146
+ def execute(self) -> Iterator[dict[str, Any]]: ...
jsonpatch.py CHANGED
@@ -55,7 +55,7 @@ _EXACT_MATCH_LIMIT = 500 ** 2
55
55
 
56
56
  # Will be parsed by setup.py to determine package metadata
57
57
  __author__ = 'Stefan Kögl <stefan@skoegl.net>'
58
- __version__ = '1.40'
58
+ __version__ = '1.41'
59
59
  __website__ = 'https://github.com/stefankoegl/python-json-patch'
60
60
  __license__ = 'BSD-3-Clause'
61
61
 
@@ -1,9 +0,0 @@
1
- jsonpatch.py,sha256=nBwD-qjBsmCmxqudmG8hfFMRb1Qd7RuqRWWD3ywSfCA,47675
2
- jsonpatch_cli.py,sha256=ooxDB62_Vcx6ryCbyMHItkNgmZjp73ZOyxgV1IAcdVI,6274
3
- jsonpatch-1.40.dist-info/licenses/AUTHORS,sha256=hOtEnBGbfDegKjzMDEl5vuVJyczbI2PlYE2ho4LjGNQ,140
4
- jsonpatch-1.40.dist-info/licenses/LICENSE,sha256=Q5PrZzP6HjZ_QXabOC9PG-e_Da6x4kPtkrP12Lr9I28,1481
5
- jsonpatch-1.40.dist-info/METADATA,sha256=-V0jnbQmTPNGNAkMXQR6I59RsVv09ORksXEv7fT8lYU,3672
6
- jsonpatch-1.40.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
7
- jsonpatch-1.40.dist-info/entry_points.txt,sha256=aY9ormBVRZHHDaAeMcdqTBwZ-ax7GvBTSQ33I75xtZM,98
8
- jsonpatch-1.40.dist-info/top_level.txt,sha256=efUF341HUk8WcQKnFt8ZLKEKNrm1kFT76Flr38Fjno0,24
9
- jsonpatch-1.40.dist-info/RECORD,,