diff --git a/CHANGELOG.md b/CHANGELOG.md index b2c4ae7..c05ceb3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Python JSONPath Change Log +## Version 1.2.3 + +**Fixes** + +- Relax type hints on `JSONPatch.apply()`. Some static type checkers were complaining. + ## Version 1.2.2 **Fixes** diff --git a/jsonpath/__about__.py b/jsonpath/__about__.py index 433a7d9..a0a9afb 100644 --- a/jsonpath/__about__.py +++ b/jsonpath/__about__.py @@ -1,4 +1,4 @@ # SPDX-FileCopyrightText: 2023-present James Prior # # SPDX-License-Identifier: MIT -__version__ = "1.2.2" +__version__ = "1.2.3" diff --git a/jsonpath/exceptions.py b/jsonpath/exceptions.py index 7e61acb..f3556a9 100644 --- a/jsonpath/exceptions.py +++ b/jsonpath/exceptions.py @@ -1,4 +1,5 @@ """JSONPath exceptions.""" + from __future__ import annotations from typing import TYPE_CHECKING diff --git a/jsonpath/patch.py b/jsonpath/patch.py index ce5c054..bd2972d 100644 --- a/jsonpath/patch.py +++ b/jsonpath/patch.py @@ -7,6 +7,7 @@ from abc import ABC from abc import abstractmethod from io import IOBase +from typing import Any from typing import Dict from typing import Iterable from typing import List @@ -74,7 +75,7 @@ def apply( else: parent.insert(int(target), self.value) elif isinstance(parent, MutableMapping): - parent[target] = self.value + parent[str(target)] = self.value else: raise JSONPatchError( f"unexpected operation on {parent.__class__.__name__!r}" @@ -183,7 +184,7 @@ def apply( elif isinstance(parent, MutableMapping): if obj is UNDEFINED: raise JSONPatchError("can't remove nonexistent property") - del parent[self.path.parts[-1]] + del parent[str(self.path.parts[-1])] else: raise JSONPatchError( f"unexpected operation on {parent.__class__.__name__!r}" @@ -221,7 +222,7 @@ def apply( elif isinstance(parent, MutableMapping): if obj is UNDEFINED: raise JSONPatchError("can't replace nonexistent property") - parent[self.path.parts[-1]] = self.value + parent[str(self.path.parts[-1])] = self.value else: raise JSONPatchError( f"unexpected operation on {parent.__class__.__name__!r}" @@ -259,7 +260,7 @@ def apply( if isinstance(source_parent, MutableSequence): del source_parent[int(self.source.parts[-1])] if isinstance(source_parent, MutableMapping): - del source_parent[self.source.parts[-1]] + del source_parent[str(self.source.parts[-1])] dest_parent, _ = self.dest.resolve_parent(data) @@ -270,7 +271,7 @@ def apply( if isinstance(dest_parent, MutableSequence): dest_parent.insert(int(self.dest.parts[-1]), source_obj) elif isinstance(dest_parent, MutableMapping): - dest_parent[self.dest.parts[-1]] = source_obj + dest_parent[str(self.dest.parts[-1])] = source_obj else: raise JSONPatchError( f"unexpected operation on {dest_parent.__class__.__name__!r}" @@ -312,7 +313,7 @@ def apply( if isinstance(dest_parent, MutableSequence): dest_parent.insert(int(self.dest.parts[-1]), copy.deepcopy(source_obj)) elif isinstance(dest_parent, MutableMapping): - dest_parent[self.dest.parts[-1]] = copy.deepcopy(source_obj) + dest_parent[str(self.dest.parts[-1])] = copy.deepcopy(source_obj) else: raise JSONPatchError( f"unexpected operation on {dest_parent.__class__.__name__!r}" @@ -628,7 +629,7 @@ def test(self: Self, path: Union[str, JSONPointer], value: object) -> Self: def apply( self, - data: Union[str, IOBase, MutableSequence[object], MutableMapping[str, object]], + data: Union[str, IOBase, MutableSequence[object], MutableMapping[str, Any]], ) -> object: """Apply all operations from this patch to _data_. @@ -676,7 +677,7 @@ def asdicts(self) -> List[Dict[str, object]]: def apply( patch: Union[str, IOBase, Iterable[Mapping[str, object]], None], - data: Union[str, IOBase, MutableSequence[object], MutableMapping[str, object]], + data: Union[str, IOBase, MutableSequence[object], MutableMapping[str, Any]], *, unicode_escape: bool = True, uri_decode: bool = False,