nested-diff
Advanced tools
@@ -23,3 +23,3 @@ # Copyright 2018-2025 Michael Samoglyadov | ||
| __version__ = '1.8.0' | ||
| __version__ = '1.9.0' | ||
| __author__ = 'Michael Samoglyadov' | ||
@@ -104,2 +104,3 @@ __license__ = 'Apache License, Version 2.0' | ||
| self, | ||
| *, | ||
| A=True, # noqa: N803 | ||
@@ -258,3 +259,3 @@ N=True, # noqa: N803 | ||
| def __init__(self, handlers=None, sort_keys=False): | ||
| def __init__(self, *, handlers=None, sort_keys=False): | ||
| """Initialize iterator. | ||
@@ -261,0 +262,0 @@ |
+72
-20
@@ -60,3 +60,3 @@ # Copyright 2019-2024 Michael Samoglyadov | ||
| import json | ||
| import json # noqa: PLC0415 | ||
@@ -349,3 +349,3 @@ return json.loads(opts) | ||
| import json | ||
| import json # noqa: PLC0415 | ||
@@ -388,3 +388,3 @@ self.encoder = json.JSONEncoder(**self.get_opts(kwargs)) | ||
| import json | ||
| import json # noqa: PLC0415 | ||
@@ -410,4 +410,4 @@ self.decoder = json.JSONDecoder(**self.get_opts(kwargs)) | ||
| import configparser | ||
| import io | ||
| import configparser # noqa: PLC0415 | ||
| import io # noqa: PLC0415 | ||
@@ -437,3 +437,3 @@ self.encoder = configparser.ConfigParser(**self.get_opts(kwargs)) | ||
| import configparser | ||
| import configparser # noqa: PLC0415 | ||
@@ -465,3 +465,3 @@ self.decoder = configparser.ConfigParser(**kwargs) | ||
| import pprint | ||
| import pprint # noqa: PLC0415 | ||
@@ -504,3 +504,3 @@ self.codec = pprint.PrettyPrinter(**self.get_opts(kwargs)) | ||
| import tomli_w | ||
| import tomli_w # noqa: PLC0415 | ||
@@ -522,5 +522,5 @@ self.codec = tomli_w | ||
| if sys.version_info >= (3, 11): | ||
| import tomllib # pragma nocover | ||
| import tomllib # pragma nocover # noqa: PLC0415 | ||
| else: | ||
| import tomli as tomllib # pragma nocover | ||
| import tomli as tomllib # pragma nocover # noqa: PLC0415 | ||
@@ -546,8 +546,8 @@ self.codec = tomllib | ||
| import yaml | ||
| import yaml # noqa: PLC0415 | ||
| try: | ||
| from yaml import CSafeDumper as ImportedYamlDumper | ||
| from yaml import CSafeDumper as ImportedYamlDumper # noqa: PLC0415 | ||
| except ImportError: | ||
| from yaml import SafeDumper as ImportedYamlDumper | ||
| from yaml import SafeDumper as ImportedYamlDumper # noqa: PLC0415 | ||
@@ -600,12 +600,14 @@ class _YamlDumper(ImportedYamlDumper): | ||
| import yaml | ||
| import yaml # noqa: PLC0415 | ||
| try: | ||
| from yaml import CSafeLoader as YamlLoader | ||
| from yaml import CSafeLoader as YamlLoader # noqa: PLC0415 | ||
| except ImportError: | ||
| from yaml import SafeLoader as YamlLoader | ||
| from yaml import SafeLoader as YamlLoader # noqa: PLC0415 | ||
| from yaml.nodes import MappingNode as YamlMappingNode | ||
| from yaml.nodes import ScalarNode as YamlScalarNode | ||
| from yaml.nodes import SequenceNode as YamlSequenceNode | ||
| from yaml.nodes import ( # noqa: PLC0415 | ||
| MappingNode as YamlMappingNode, | ||
| ScalarNode as YamlScalarNode, | ||
| SequenceNode as YamlSequenceNode, | ||
| ) | ||
@@ -634,5 +636,55 @@ self.opts = self.get_opts(kwargs) | ||
| """Parse YAML string.""" | ||
| return self.yaml.load(data, Loader=self.yaml_loader, **self.opts) | ||
| items = list( | ||
| self.yaml.load_all(data, Loader=self.yaml_loader, **self.opts), | ||
| ) | ||
| if len(items) == 1: | ||
| return items[0] | ||
| return ListOfDocuments(items) | ||
| class ListOfDocuments: | ||
| """Wrapper to represent bunch of documents like YAML stream.""" | ||
| def __init__(self, items): | ||
| """Initialize wrapper. | ||
| Args: | ||
| items: list of documents. | ||
| """ | ||
| self.items = items | ||
| def __repr__(self): | ||
| """Repr for wrapper.""" | ||
| return f'ListOfDocuments({self.items})' | ||
| class ListOfDocumentsHandler(nested_diff.handlers.ListHandler): | ||
| """ListOfDocuments handler.""" | ||
| extension_id = 'nested_diff.ListOfDocuments' | ||
| handled_type = ListOfDocuments | ||
| def diff(self, differ, a, b): | ||
| """Calculate diff for two ListOfDocuments objects. | ||
| Args: | ||
| differ: nested_diff.Differ object. | ||
| a: First object to diff. | ||
| b: Second object to diff. | ||
| Returns: | ||
| Tuple: equality flag and nested diff. | ||
| """ | ||
| equal, diff = differ.diff(a.items, b.items) | ||
| if diff: | ||
| diff['E'] = self.extension_id | ||
| return equal, diff | ||
| class YamlNode: | ||
@@ -639,0 +691,0 @@ """Wrapper to represent YAML node.""" |
@@ -61,2 +61,3 @@ # Copyright 2019-2024 Michael Samoglyadov | ||
| differ = nested_diff.Differ(**diff_opts) | ||
| differ.set_handler(nested_diff.cli.ListOfDocumentsHandler()) | ||
| differ.set_handler(nested_diff.cli.YamlNodeHandler()) | ||
@@ -282,3 +283,3 @@ | ||
| """ | ||
| import nested_diff.formatters | ||
| import nested_diff.formatters # noqa: PLC0415 | ||
@@ -294,2 +295,3 @@ if fmt == 'term': | ||
| self.encoder = fmt_class(**self.get_opts(kwargs)) | ||
| self.encoder.set_handler(nested_diff.cli.ListOfDocumentsHandler()) | ||
| self.encoder.set_handler(nested_diff.cli.YamlNodeHandler()) | ||
@@ -296,0 +298,0 @@ |
@@ -30,2 +30,3 @@ # Copyright 2019-2024 Michael Samoglyadov | ||
| self, | ||
| *, | ||
| handlers=None, | ||
@@ -32,0 +33,0 @@ indent=' ', |
@@ -151,3 +151,3 @@ # Copyright 2022-2024 Michael Samoglyadov | ||
| def __init__(self, nans_equal=False): | ||
| def __init__(self, *, nans_equal=False): | ||
| """Initialize handler. | ||
@@ -154,0 +154,0 @@ |
+3
-2
| Metadata-Version: 2.4 | ||
| Name: nested_diff | ||
| Version: 1.8.0 | ||
| Version: 1.9.0 | ||
| Summary: Recursive diff and patch for nested structures. | ||
@@ -25,2 +25,3 @@ Keywords: diff,nested-diff,recursive-diff,nested-data,data-structures | ||
| Classifier: Programming Language :: Python :: 3.13 | ||
| Classifier: Programming Language :: Python :: 3.14 | ||
| Classifier: Programming Language :: Python :: Implementation :: CPython | ||
@@ -41,3 +42,3 @@ Classifier: Programming Language :: Python :: Implementation :: PyPy | ||
| Requires-Dist: pytest-ruff ; extra == "test" | ||
| Requires-Dist: ruff==0.11.13 ; extra == "test" | ||
| Requires-Dist: ruff==0.14.8 ; extra == "test" | ||
| Project-URL: Homepage, https://github.com/mr-mixas/Nested-Diff.py | ||
@@ -44,0 +45,0 @@ Project-URL: Repository, https://github.com/mr-mixas/Nested-Diff.py.git |
+5
-2
@@ -34,2 +34,3 @@ [build-system] | ||
| 'Programming Language :: Python :: 3.13', | ||
| 'Programming Language :: Python :: 3.14', | ||
| 'Programming Language :: Python :: Implementation :: CPython', | ||
@@ -60,3 +61,3 @@ 'Programming Language :: Python :: Implementation :: PyPy', | ||
| 'pytest-ruff', | ||
| 'ruff==0.11.13', | ||
| 'ruff==0.14.8', | ||
| ] | ||
@@ -101,3 +102,2 @@ | ||
| 'EM102', # Exception must not use an f-string literal | ||
| 'FBT002', # TODO: enable | ||
| 'PTH', # ... should be replaced by `Path... | ||
@@ -119,3 +119,6 @@ 'SIM105', # contextlib.suppress is slower than try-except-pass | ||
| [tool.ruff.lint.isort] | ||
| combine-as-imports = true | ||
| [tool.ruff.lint.pydocstyle] | ||
| convention = 'google' |
Alert delta unavailable
Currently unable to show alert delta for PyPI packages.
102370
1.69%2094
1.9%