Skip to content

Commit 4517dab

Browse files
committed
fix misc things about jsonpatch correction
1 parent d690200 commit 4517dab

File tree

3 files changed

+24
-12
lines changed

3 files changed

+24
-12
lines changed

src/idom/core/_fixed_jsonpatch.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# type: ignore
2+
13
"""A patched version of jsonpatch
24
35
We need this because of: https://github.com/stefankoegl/python-json-patch/issues/138
@@ -9,28 +11,37 @@
911
from jsonpatch import _ST_REMOVE
1012
from jsonpatch import DiffBuilder as _DiffBuilder
1113
from jsonpatch import JsonPatch as _JsonPatch
12-
from jsonpatch import RemoveOperation, _path_join
14+
from jsonpatch import RemoveOperation, _path_join, basestring
15+
from jsonpointer import JsonPointer
1316

1417

15-
def apply_patch(doc, patch, in_place=False):
16-
if isinstance(patch, (str, bytes)):
17-
patch = JsonPatch.from_string(patch)
18+
def apply_patch(doc, patch, in_place=False, pointer_cls=JsonPointer):
19+
if isinstance(patch, basestring):
20+
patch = JsonPatch.from_string(patch, pointer_cls=pointer_cls)
1821
else:
19-
patch = JsonPatch(patch)
22+
patch = JsonPatch(patch, pointer_cls=pointer_cls)
2023
return patch.apply(doc, in_place)
2124

2225

23-
def make_patch(src, dst):
24-
return JsonPatch.from_diff(src, dst)
26+
def make_patch(src, dst, pointer_cls=JsonPointer):
27+
return JsonPatch.from_diff(src, dst, pointer_cls=pointer_cls)
2528

2629

2730
class JsonPatch(_JsonPatch):
2831
@classmethod
29-
def from_diff(cls, src, dst, optimization=True):
30-
builder = DiffBuilder()
32+
def from_diff(
33+
cls,
34+
src,
35+
dst,
36+
optimization=True,
37+
dumps=None,
38+
pointer_cls=JsonPointer,
39+
):
40+
json_dumper = dumps or cls.json_dumper
41+
builder = DiffBuilder(src, dst, json_dumper, pointer_cls=pointer_cls)
3142
builder._compare_values("", None, src, dst)
3243
ops = list(builder.execute())
33-
return cls(ops)
44+
return cls(ops, pointer_cls=pointer_cls)
3445

3546

3647
class DiffBuilder(_DiffBuilder):

src/idom/core/dispatcher.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
from idom.utils import Ref
2424

25-
from ._fixed_jsonpatch import apply_patch, make_patch
25+
from ._fixed_jsonpatch import apply_patch, make_patch # type: ignore
2626
from .layout import LayoutEvent, LayoutUpdate
2727
from .proto import LayoutType, VdomJson
2828

src/idom/testing.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,10 @@ def assert_idom_logged(
202202
message_pattern.findall(record.getMessage())
203203
# error type matches
204204
and (
205-
not error_type
205+
error_type is None
206206
or (
207207
record.exc_info is not None
208+
and record.exc_info[0] is not None
208209
and issubclass(record.exc_info[0], error_type)
209210
)
210211
)

0 commit comments

Comments
 (0)