diff method doc string updates#137
Conversation
dictdiffer/__init__.py
Outdated
| - Key/value pairs for 'add' and 'remove'; keys for lists are indexes | ||
| - Previous/new values for 'change', key being a part of the path in this case | ||
| - Several value tuples sharing the same op and path are wrapped in a | ||
| list, unless you specify `expand=True`, in which case they all |
There was a problem hiding this comment.
| list, unless you specify `expand=True`, in which case they all | |
| list, unless you specify `expand=True`, in which case they all |
| - Previous/new values for 'change', key being a part of the path in this case | ||
| - Several value tuples sharing the same op and path are wrapped in a | ||
| list, unless you specify `expand=True`, in which case they all | ||
| get a separate (op, path, values) tuple. |
There was a problem hiding this comment.
| get a separate (op, path, values) tuple. | |
| get a separate (op, path, values) tuple. |
| - `path` is by default a dot-separated string of keys from the root of the | ||
| structure to the point of difference. | ||
| - If parameter `dot_notation` is set to False, path is a list of | ||
| separate key strings instead. |
There was a problem hiding this comment.
| separate key strings instead. | |
| separate key strings instead. |
|
@jirikuncar I guess you wanted to ping @mikaelho instead 😉 |
| {'_dictdiffer_value_key': {'type': 'datetime.date', 'value': '2021-07-06'}} | ||
| """ | ||
| transformed_value = False | ||
| for cls, transform in TRANSFORMS: |
There was a problem hiding this comment.
I am not a big fun of global variables. Would it be possible to pass transformations as parameters to diff function and propagate them down? I am afraid that the performance will suffer for "dict"-only cases since you will always iterate through this list.
| def add_transform(value_sample, represent, reconstruct): | ||
| TRANSFORMS.append((type(value_sample), {'from': represent, 'to': reconstruct})) | ||
| assert reconstruct(represent(value_sample)) == value_sample, ( | ||
| f'Could not reconstruct ({type(represent(value_sample)).__name__}) {represent(value_sample)} ' | ||
| f'to ({type(value_sample).__name__}) {value_sample}' | ||
| ) |
There was a problem hiding this comment.
This could be avoided by allowing users to pass own list with transformations.
| def allow_import(*module_names): | ||
| for module in module_names: | ||
| importlib.import_module(module) | ||
| ALLOW_IMPORT.extend(module_names) |
There was a problem hiding this comment.
similar reasoning as TRANSFORMS
| if isinstance(value, list): | ||
| key = int(key) | ||
| value = value[key] | ||
| value = value.__dict__ if key == '__dict__' else value[key] |
There was a problem hiding this comment.
| value = value.__dict__ if key == '__dict__' else value[key] | |
| try: | |
| value = value[key] | |
| except KeyError: | |
| if key == '__dict__': | |
| value = value.__dict__ | |
| else: | |
| raise |
dictdiffer/version.py
Outdated
| """Version information for dictdiffer package.""" | ||
|
|
||
| __version__ = '0.8.2.dev2+dirty' | ||
| __version__ = '0.6.2.dev32+dirty' |
| @@ -639,6 +663,34 @@ def test_in_place_patch_and_revert(self): | |||
| patched_in_place = patch(changes, first, in_place=True) | |||
| assert first == patched_in_place | |||
|
|
|||
There was a problem hiding this comment.
TODO
diff({'__dict__': {'a': 1}}, {'__dict__': {'a': 2}})
jirikuncar
left a comment
There was a problem hiding this comment.
Please see my comments and revert:
pytest.ini_disable → pytest.ini
As discussed earlier.