Skip to content
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

add unchanged path + values in diff report #481

Open
Hazedd opened this issue Sep 9, 2024 · 0 comments
Open

add unchanged path + values in diff report #481

Hazedd opened this issue Sep 9, 2024 · 0 comments

Comments

@Hazedd
Copy link

Hazedd commented Sep 9, 2024

Feature Request: Include Unchanged Values in DeepDiff Report

I'm looking for a way to retrieve all attributes, including those that haven't changed. I might be missing a method to achieve this, and I'm feeling a bit stuck... so i have this feature request.

Overview

I would like to propose a new feature for the deepdiff library that would enhance its reporting capabilities by including unchanged values in the comparison report. Currently, deepdiff provides detailed reports on changed items, but it does not explicitly list the values that remain unchanged between data structures.

Benefits

  • Comprehensive Reporting: Users will be able to see not only what has changed but also what remains the same, providing a fuller picture of the differences.
  • Enhanced Transparency: By including unchanged values, users can better understand the complete context of the comparison.

Proposed Feature code adjustments

Add optional add_unchanged Parameter

Introduce an optional parameter, add_unchanged, to the DeepDiff class. This parameter should control whether unchanged values are included in the comparison report.

  • Parameter Name: add_unchanged
  • Type: bool
  • Default Value: False
  • Description: When set to True, unchanged values will be included in the report.
class DeepDiff(ResultDict, SerializationMixin, DistanceMixin, Base):
    ....
    def __init__(self,
        .....
        add_unchanged=False, 
        ....
    )

    if _parameters:
        self.__dict__.update(_parameters)
    else:
        ....
        self.add_unchanged = add_unchanged
....

Update _diff Method

Modify the _diff method to include unchanged values in the report if the add_unchanged parameter is set to True. The method should handle the inclusion of these values and ensure they are properly reported.

if level.t1 is level.t2:
    if self.add_unchanged:
        self._report_result('values_unchanged', level, local_tree=local_tree)
    return

Modify REPORT_KEYS

Update the REPORT_KEYS dictionary to add an entry for values_unchanged, so the new report type is recognized and handled appropriately.

REPORT_KEYS = {
    ...
    "values_unchanged"
}

Enhance Result Classes

Extend the TextResult handling classe (DeltaResult should not have unchanged values and TreeResult should work whitout changes) to include support for the values_unchanged key. This will involve:

  • Adding a values_unchanged key to the initialization of the result dictionaries.
  • Implementing logic to populate and handle unchanged values in the results.

TextResult adjustments

def __init__(self, tree_results=None, verbose_level=1):
    ....
    self.update({
        ....
    "values_unchanged": dict_(),

    })

def _from_tree_results(self, tree):
    ....
    self._from_tree_default(tree, 'values_unchanged')
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

No branches or pull requests

1 participant