Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit aa46bd4

Browse files
committed
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.
1 parent 6ed63f3 commit aa46bd4

1 file changed

Lines changed: 11 additions & 11 deletions

File tree

Doc/library/stdtypes.rst

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -692,16 +692,16 @@ number, :class:`float`, or :class:`complex`::
692692
m, n = m // P, n // P
693693

694694
if n % P == 0:
695-
hash_ = sys.hash_info.inf
695+
hash_value = sys.hash_info.inf
696696
else:
697697
# Fermat's Little Theorem: pow(n, P-1, P) is 1, so
698698
# pow(n, P-2, P) gives the inverse of n modulo P.
699-
hash_ = (abs(m) % P) * pow(n, P - 2, P) % P
699+
hash_value = (abs(m) % P) * pow(n, P - 2, P) % P
700700
if m < 0:
701-
hash_ = -hash_
702-
if hash_ == -1:
703-
hash_ = -2
704-
return hash_
701+
hash_value = -hash_value
702+
if hash_value == -1:
703+
hash_value = -2
704+
return hash_value
705705

706706
def hash_float(x):
707707
"""Compute the hash of a float x."""
@@ -716,13 +716,13 @@ number, :class:`float`, or :class:`complex`::
716716
def hash_complex(z):
717717
"""Compute the hash of a complex number z."""
718718

719-
hash_ = hash_float(z.real) + sys.hash_info.imag * hash_float(z.imag)
719+
hash_value = hash_float(z.real) + sys.hash_info.imag * hash_float(z.imag)
720720
# do a signed reduction modulo 2**sys.hash_info.width
721721
M = 2**(sys.hash_info.width - 1)
722-
hash_ = (hash_ & (M - 1)) - (hash & M)
723-
if hash_ == -1:
724-
hash_ == -2
725-
return hash_
722+
hash_value = (hash_value & (M - 1)) - (hash_value & M)
723+
if hash_value == -1:
724+
hash_value = -2
725+
return hash_value
726726

727727
.. _typeiter:
728728

0 commit comments

Comments
 (0)