Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
fec6620d
Kaydet (Commit)
fec6620d
authored
Kas 13, 2010
tarafından
Mark Dickinson
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Make Fraction(-1).__hash__() return -2 rather than -1 (see issue 10356).
üst
24854cac
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
9 additions
and
6 deletions
+9
-6
fractions.py
Lib/fractions.py
+3
-6
test_fractions.py
Lib/test/test_fractions.py
+3
-0
NEWS
Misc/NEWS
+3
-0
No files found.
Lib/fractions.py
Dosyayı görüntüle @
fec6620d
...
...
@@ -528,12 +528,8 @@ class Fraction(numbers.Rational):
return
Fraction
(
round
(
self
/
shift
)
*
shift
)
def
__hash__
(
self
):
"""hash(self)
"""hash(self)
"""
Tricky because values that are exactly representable as a
float must have the same hash as that float.
"""
# XXX since this method is expensive, consider caching the result
# In order to make sure that the hash of a Fraction agrees
...
...
@@ -550,7 +546,8 @@ class Fraction(numbers.Rational):
hash_
=
_PyHASH_INF
else
:
hash_
=
abs
(
self
.
_numerator
)
*
dinv
%
_PyHASH_MODULUS
return
hash_
if
self
>=
0
else
-
hash_
result
=
hash_
if
self
>=
0
else
-
hash_
return
-
2
if
result
==
-
1
else
result
def
__eq__
(
a
,
b
):
"""a == b"""
...
...
Lib/test/test_fractions.py
Dosyayı görüntüle @
fec6620d
...
...
@@ -546,6 +546,9 @@ class FractionTest(unittest.TestCase):
self
.
assertEquals
(
hash
(
2.5
),
hash
(
F
(
5
,
2
)))
self
.
assertEquals
(
hash
(
10
**
50
),
hash
(
F
(
10
**
50
)))
self
.
assertNotEquals
(
hash
(
float
(
10
**
23
)),
hash
(
F
(
10
**
23
)))
# Check that __hash__ produces the same value as hash(), for
# consistency with int and Decimal. (See issue #10356.)
self
.
assertEquals
(
hash
(
F
(
-
1
)),
F
(
-
1
)
.
__hash__
())
def
testApproximatePi
(
self
):
# Algorithm borrowed from
...
...
Misc/NEWS
Dosyayı görüntüle @
fec6620d
...
...
@@ -63,6 +63,9 @@ Core and Builtins
Library
-------
- Fix Fraction.__hash__ so that Fraction.__hash__(-1) is -2. (See
also issue #10356.)
- Issue #4471: Add the IMAP.starttls() method to enable encryption on
standard IMAP4 connections. Original patch by Lorenzo M. Catucci.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment