File tree Expand file tree Collapse file tree 3 files changed +22
-0
lines changed
Expand file tree Collapse file tree 3 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -97,3 +97,4 @@ pip install dirty-equals
9797```
9898
9999** dirty-equals** requires ** Python 3.7+** .
100+
Original file line number Diff line number Diff line change 1+ # Internals
2+ ## How the magic of ` DirtyEquals.__eq__ ` works?
3+ When you call ` x == y ` , Python first calls ` x.__eq__(y) ` . This would not help us
4+ much, because we would have to keep an eye on order of the arguments when
5+ comparing to ` DirtyEquals ` objects. But that's where were another feature of
6+ Python comes in.
7+
8+ When ` x.__eq__(y) ` returns the ` NotImplemented ` object, then Python will try to
9+ call ` y.__eq__(x) ` . Objects in the standard library return that value when they
10+ don't know how to compare themselves to objects of ` type(y) ` (Without checking
11+ the C source I can't be certain if this assumption holds for all classes, but it
12+ works for all the basic ones).
13+ In [ ` pathlib.PurePath ` ] ( https://github.com/python/cpython/blob/aebbd7579a421208f48dd6884b67dbd3278b71ad/Lib/pathlib.py#L751 )
14+ you can see an example how that is implemented in Python.
15+
16+ > By default, object implements ` __eq__() ` by using ` is ` ,
17+ > returning ` NotImplemented ` in the case of a false comparison:
18+ > ` True if x is y else NotImplemented ` .
19+
20+ See the Python documentation for more information ([ ` object.__eq__ ` ] ( https://docs.python.org/3/reference/datamodel.html#object.__eq__ ) ).
Original file line number Diff line number Diff line change 4444 - types/boolean.md
4545 - types/other.md
4646 - types/custom.md
47+ - Internals : internals.md
4748
4849markdown_extensions :
4950 - toc :
You can’t perform that action at this time.
0 commit comments