DeepDiff pathlib.PosixPath objects
First off, deepdiff is great. Thanks.
I found the following behavior somewhat surprising. (The failure is on the last line, my expectations are set on the preceeding lines)
import pathlib
from deepdiff import DeepDiff
# Great...
p1='foobar'
p2='barfoo'
assert p1 != p2
assert not p1.__eq__(p2)
assert bool(DeepDiff(p1, p2)) is True # True == not-empty
# Huh?...
pp1=pathlib.PosixPath(p1)
pp2=pathlib.PosixPath(p2)
assert pp1 != pp2
assert not pp1.__eq__(pp2)
assert bool(DeepDiff(pp1, pp2)) is True # True == not-empty
I just verified this with the master branch.
I dug into the code a bit and found the following:
- deepdiff calls
__diff_obj()on the pathlib.PosixPath objects - these objects have no
__dict__ - these objects have empty slots (e.g.
bool(pp1.__slots__) is False).
So that's how the failure to detect the diff goes down. I have no idea about the expected behavior.
So, I'm perty new to python, but my naive expectations would be that before diffing the __dict__ or a dict based on the __slots__ of an object, you'd first check that object for __eq__ and use that to compare the objects. Or, if that didnt make sense, maybe there would be an optional list of types to __eq__ passed to DeepDiff instead of traversing __dict__? I honestly dont know where/how these ideas or expectations might fit in to how deepdiff is/should be structured... or if there is already something I'm missing that solves this.
Above I'm giving the MRE, but in my use case I have these pathlib.PosixPath objects inside other objects (which dont have__eq__). Thanks and I'm happy to be helpful however I can since I will rely on deepdiff!
(I also found dunders werent designed for communication in markdown! geeseess) Cheers,
see #104.