crusaderky / recursive_diff

Recursively compare Python data structures
Apache License 2.0
14 stars 2 forks source link

Handling cycles in objects #24

Open viraptor opened 1 week ago

viraptor commented 1 week ago

Currently the implementation will happily descend into the objects forever. It would be great if it handled cycles by keeping a history of which objects are already being traversed.

So something like:

foo = {'a': None, 'b': 123}
foo['a'] = foo

Would ensure that b has the same value, but a points at the same object in the path. Or specifically at an object the same number of steps up the path.

fooL = {'a': None, 'b': 123}
fooL['a'] = fooL
fooR = {'a': None, 'b': 123}
fooR['a'] = fooR
recursive_diff(fooL, fooR) <- should find no differences and not get stuck
crusaderky commented 7 hours ago

Thanks for spotting this! Would you be available to write a PR?