Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,4 @@ pip install dirty-equals
```

**dirty-equals** requires **Python 3.7+**.

20 changes: 20 additions & 0 deletions docs/internals.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Internals
## How the magic of `DirtyEquals.__eq__` works?
When you call `x == y`, Python first calls `x.__eq__(y)`. This would not help us
much, because we would have to keep an eye on order of the arguments when
comparing to `DirtyEquals` objects. But that's where were another feature of
Python comes in.

When `x.__eq__(y)` returns the `NotImplemented` object, then Python will try to
call `y.__eq__(x)`. Objects in the standard library return that value when they
don't know how to compare themselves to objects of `type(y)` (Without checking
the C source I can't be certain if this assumption holds for all classes, but it
works for all the basic ones).
In [`pathlib.PurePath`](https://github.com/python/cpython/blob/aebbd7579a421208f48dd6884b67dbd3278b71ad/Lib/pathlib.py#L751)
you can see an example how that is implemented in Python.

> By default, object implements `__eq__()` by using `is`,
> returning `NotImplemented` in the case of a false comparison:
> `True if x is y else NotImplemented`.

See the Python documentation for more information ([`object.__eq__`](https://docs.python.org/3/reference/datamodel.html#object.__eq__)).
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ nav:
- types/boolean.md
- types/other.md
- types/custom.md
- Internals: internals.md

markdown_extensions:
- toc:
Expand Down