Skip to content

Conversation

@mikaelho
Copy link
Contributor

As discussed earlier.

- 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
separate key strings instead.
separate key strings instead.

@jirikuncar
Copy link
Member

jirikuncar commented Jan 6, 2020

@michamos @mikaelho thank you for your contribution. Please make sure that it's correctly formatted so it can be build without warnings.

@michamos
Copy link

michamos commented Jan 6, 2020

@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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +511 to +516
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}'
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similar reasoning as TRANSFORMS

if isinstance(value, list):
key = int(key)
value = value[key]
value = value.__dict__ if key == '__dict__' else value[key]
Copy link
Member

@jirikuncar jirikuncar Jul 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
value = value.__dict__ if key == '__dict__' else value[key]
try:
value = value[key]
except KeyError:
if key == '__dict__':
value = value.__dict__
else:
raise

"""Version information for dictdiffer package."""

__version__ = '0.8.2.dev2+dirty'
__version__ = '0.6.2.dev32+dirty'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert

assert patched_copy == reverted_in_place
patched_in_place = patch(changes, first, in_place=True)
assert first == patched_in_place

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO

diff({'__dict__': {'a': 1}}, {'__dict__': {'a': 2}})

Copy link
Member

@jirikuncar jirikuncar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see my comments and revert:

pytest.ini_disable  → pytest.ini

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants