diff --git a/docs/advanced/classes.rst b/docs/advanced/classes.rst index b3da0378c0..db00ef0506 100644 --- a/docs/advanced/classes.rst +++ b/docs/advanced/classes.rst @@ -695,6 +695,13 @@ throwing a type error. To use the more convenient ``py::self`` notation, the additional header file :file:`pybind11/operators.h` must be included. + +.. note:: + + A class that overrides ``__eq__()`` and does not define ``__hash__()`` will have its ``__hash__()`` implicitly set. + This is a deviation from the standard Python behaviour where ``__hash__()`` is set to ``None`` when overriding ``__eq__()``. To restore the default behaviour + one can use ``.attr("__hash__") = py::none()``. When set ``None`` the class will raise an appropriate TypeError when a program attempts to retrieve their + hash value, and will also be correctly identified as unhashable when checking ``isinstance(obj, collections.abc.Hashable)``. .. seealso::