Skip to content

Commit

Permalink
Rename to make_patch
Browse files Browse the repository at this point in the history
  • Loading branch information
nineteendo committed Aug 20, 2024
1 parent 7d8f9f1 commit 0cab408
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
4 changes: 2 additions & 2 deletions docs/source/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ Using :class:`decimal.Decimal` instead of :class:`float`::
>>> json.dump(Decimal("1.1"))
1.1

Comparing two Python objects::
Make a patch from two Python objects::

>>> import jsonyx as json
>>> json.diff([1, 2, 3, 5], [1, 3, 4, 5])
>>> json.make_patch([1, 2, 3, 5], [1, 3, 4, 5])
[{'op': 'del', 'path': '$[1]'}, {'op': 'insert', 'path': '$[2]', 'value': 4}]

Applying a patch::
Expand Down
4 changes: 2 additions & 2 deletions src/jsonyx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
"Manipulator",
"apply_patch",
"detect_encoding",
"diff",
"dump",
"dumps",
"format_syntax_error",
"load",
"load_query_value",
"loads",
"make_patch",
"read",
"run_filter_query",
"run_select_query",
Expand All @@ -36,7 +36,7 @@
from typing import TYPE_CHECKING, Any, Literal

from jsonyx._decoder import DuplicateKey, JSONSyntaxError, make_scanner
from jsonyx._differ import diff
from jsonyx._differ import make_patch
from jsonyx._encoder import make_encoder
from jsonyx._manipulator import Manipulator
from jsonyx.allow import NOTHING
Expand Down
5 changes: 3 additions & 2 deletions src/jsonyx/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
from typing import Any, Literal, cast

from jsonyx import (
Decoder, Encoder, JSONSyntaxError, Manipulator, diff, format_syntax_error,
Decoder, Encoder, JSONSyntaxError, Manipulator, format_syntax_error,
make_patch,
)
from jsonyx.allow import EVERYTHING, NOTHING

Expand Down Expand Up @@ -199,7 +200,7 @@ def _run(args: _Namespace) -> None:
if args.command == "diff":
args = cast(_DiffNameSpace, args)
old_input_obj: object = decoder.read(args.old_input_filename)
output_obj: Any = diff(old_input_obj, input_obj)
output_obj: Any = make_patch(old_input_obj, input_obj)
if len(output_obj) == 1:
output_obj = output_obj[0]
elif args.command == "format":
Expand Down
10 changes: 5 additions & 5 deletions src/jsonyx/_differ.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"""JSON differ."""
from __future__ import annotations

__all__: list[str] = ["diff"]
__all__: list[str] = ["make_patch"]

import re
from itertools import starmap
Expand Down Expand Up @@ -118,8 +118,8 @@ def _diff( # noqa: C901
patch.append({"op": "set", "path": path, "value": new})


def diff(old: Any, new: Any) -> list[dict[str, Any]]:
"""Compare two Python objects and generate a diff in JSON patch format.
def make_patch(old: Any, new: Any) -> list[dict[str, Any]]:
"""Make a JSON patch from two Python objects.
:param old: the old Python object
:type old: Any
Expand All @@ -129,7 +129,7 @@ def diff(old: Any, new: Any) -> list[dict[str, Any]]:
:rtype: list[dict[str, Any]]
>>> import jsonyx as json
>>> json.diff([1, 2, 3, 5], [1, 3, 4, 5])
>>> json.make_patch([1, 2, 3, 5], [1, 3, 4, 5])
[{'op': 'del', 'path': '$[1]'}, {'op': 'insert', 'path': '$[2]', 'value': 4}]
.. versionadded:: 2.0
Expand All @@ -139,4 +139,4 @@ def diff(old: Any, new: Any) -> list[dict[str, Any]]:
return patch


diff.__module__ = "jsonyx"
make_patch.__module__ = "jsonyx"

0 comments on commit 0cab408

Please sign in to comment.