Skip to content

Fix type hints for some static type checkers #77

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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**
Expand Down
2 changes: 1 addition & 1 deletion jsonpath/__about__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2023-present James Prior <[email protected]>
#
# SPDX-License-Identifier: MIT
__version__ = "1.2.2"
__version__ = "1.2.3"
1 change: 1 addition & 0 deletions jsonpath/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""JSONPath exceptions."""

from __future__ import annotations

from typing import TYPE_CHECKING
Expand Down
17 changes: 9 additions & 8 deletions jsonpath/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}"
Expand Down Expand Up @@ -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}"
Expand Down Expand Up @@ -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}"
Expand Down Expand Up @@ -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)

Expand All @@ -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}"
Expand Down Expand Up @@ -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}"
Expand Down Expand Up @@ -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_.

Expand Down Expand Up @@ -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,
Expand Down
Loading