diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2016-12-19 12:09:55 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2016-12-19 12:09:55 (GMT) |
commit | 01e4c1175f4d0c9150f36dae4ca8ec0e6e4ac26b (patch) | |
tree | 6b05841a0527e9e17739b3cbabf91ab2e03e4bfb /Doc/reference | |
parent | 47888da90b1a40692eca23bcc77346112b1d188a (diff) | |
parent | 509476b37085abda9c8cc0fba1451cb035e0b442 (diff) | |
download | cpython-01e4c1175f4d0c9150f36dae4ca8ec0e6e4ac26b.zip cpython-01e4c1175f4d0c9150f36dae4ca8ec0e6e4ac26b.tar.gz cpython-01e4c1175f4d0c9150f36dae4ca8ec0e6e4ac26b.tar.bz2 |
Merge 3.5
Diffstat (limited to 'Doc/reference')
-rw-r--r-- | Doc/reference/datamodel.rst | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst index 82e35e5..f2a2b12 100644 --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -1338,11 +1338,14 @@ Basic customization Called by built-in function :func:`hash` and for operations on members of hashed collections including :class:`set`, :class:`frozenset`, and - :class:`dict`. :meth:`__hash__` should return an integer. The only - required property is that objects which compare equal have the same hash - value; it is advised to somehow mix together (e.g. using exclusive or) the - hash values for the components of the object that also play a part in - comparison of objects. + :class:`dict`. :meth:`__hash__` should return an integer. The only required + property is that objects which compare equal have the same hash value; it is + advised to mix together the hash values of the components of the object that + also play a part in comparison of objects by packing them into a tuple and + hashing the tuple. Example:: + + def __hash__(self): + return hash((self.name, self.nick, self.color)) .. note:: |