summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBerker Peksag <berker.peksag@gmail.com>2016-07-25 01:55:51 (GMT)
committerBerker Peksag <berker.peksag@gmail.com>2016-07-25 01:55:51 (GMT)
commitaa46bd461c1b585d967b9a9497ea872097017d99 (patch)
tree24bf024c9029857e50462423a3bb36d969fe979f
parent6ed63f31e9ca137b543cbaa5a7a61224c8a1e659 (diff)
downloadcpython-aa46bd461c1b585d967b9a9497ea872097017d99.zip
cpython-aa46bd461c1b585d967b9a9497ea872097017d99.tar.gz
cpython-aa46bd461c1b585d967b9a9497ea872097017d99.tar.bz2
Issue #27601: Improve example in the "Hashing of numeric types" section
* Fix return value of hash_compute() implementation * Rename variable names to hash_value to improve readability Patch by Emanuel Barry.
-rw-r--r--Doc/library/stdtypes.rst22
1 files changed, 11 insertions, 11 deletions
diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst
index db1c2d0..2996eef 100644
--- a/Doc/library/stdtypes.rst
+++ b/Doc/library/stdtypes.rst
@@ -692,16 +692,16 @@ number, :class:`float`, or :class:`complex`::
m, n = m // P, n // P
if n % P == 0:
- hash_ = sys.hash_info.inf
+ hash_value = sys.hash_info.inf
else:
# Fermat's Little Theorem: pow(n, P-1, P) is 1, so
# pow(n, P-2, P) gives the inverse of n modulo P.
- hash_ = (abs(m) % P) * pow(n, P - 2, P) % P
+ hash_value = (abs(m) % P) * pow(n, P - 2, P) % P
if m < 0:
- hash_ = -hash_
- if hash_ == -1:
- hash_ = -2
- return hash_
+ hash_value = -hash_value
+ if hash_value == -1:
+ hash_value = -2
+ return hash_value
def hash_float(x):
"""Compute the hash of a float x."""
@@ -716,13 +716,13 @@ number, :class:`float`, or :class:`complex`::
def hash_complex(z):
"""Compute the hash of a complex number z."""
- hash_ = hash_float(z.real) + sys.hash_info.imag * hash_float(z.imag)
+ hash_value = hash_float(z.real) + sys.hash_info.imag * hash_float(z.imag)
# do a signed reduction modulo 2**sys.hash_info.width
M = 2**(sys.hash_info.width - 1)
- hash_ = (hash_ & (M - 1)) - (hash & M)
- if hash_ == -1:
- hash_ == -2
- return hash_
+ hash_value = (hash_value & (M - 1)) - (hash_value & M)
+ if hash_value == -1:
+ hash_value = -2
+ return hash_value
.. _typeiter: