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
374274db
Kaydet (Commit)
374274db
authored
Mar 19, 2011
tarafından
Éric Araujo
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fix the total_ordering decorator to handle cross-type comparisons
that could lead to infinite recursion (closes #10042).
üst
5136867c
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
36 additions
and
8 deletions
+36
-8
functools.py
Lib/functools.py
+8
-8
test_functools.py
Lib/test/test_functools.py
+24
-0
ACKS
Misc/ACKS
+1
-0
NEWS
Misc/NEWS
+3
-0
No files found.
Lib/functools.py
Dosyayı görüntüle @
374274db
...
@@ -53,17 +53,17 @@ def wraps(wrapped,
...
@@ -53,17 +53,17 @@ def wraps(wrapped,
def
total_ordering
(
cls
):
def
total_ordering
(
cls
):
"""Class decorator that fills in missing ordering methods"""
"""Class decorator that fills in missing ordering methods"""
convert
=
{
convert
=
{
'__lt__'
:
[(
'__gt__'
,
lambda
self
,
other
:
other
<
self
),
'__lt__'
:
[(
'__gt__'
,
lambda
self
,
other
:
not
(
self
<
other
or
self
==
other
)
),
(
'__le__'
,
lambda
self
,
other
:
not
other
<
self
),
(
'__le__'
,
lambda
self
,
other
:
self
<
other
or
self
==
other
),
(
'__ge__'
,
lambda
self
,
other
:
not
self
<
other
)],
(
'__ge__'
,
lambda
self
,
other
:
not
self
<
other
)],
'__le__'
:
[(
'__ge__'
,
lambda
self
,
other
:
other
<=
self
),
'__le__'
:
[(
'__ge__'
,
lambda
self
,
other
:
not
self
<=
other
or
self
==
other
),
(
'__lt__'
,
lambda
self
,
other
:
not
other
<=
self
),
(
'__lt__'
,
lambda
self
,
other
:
self
<=
other
and
not
self
==
other
),
(
'__gt__'
,
lambda
self
,
other
:
not
self
<=
other
)],
(
'__gt__'
,
lambda
self
,
other
:
not
self
<=
other
)],
'__gt__'
:
[(
'__lt__'
,
lambda
self
,
other
:
other
>
self
),
'__gt__'
:
[(
'__lt__'
,
lambda
self
,
other
:
not
(
self
>
other
or
self
==
other
)
),
(
'__ge__'
,
lambda
self
,
other
:
not
other
>
self
),
(
'__ge__'
,
lambda
self
,
other
:
self
>
other
or
self
==
other
),
(
'__le__'
,
lambda
self
,
other
:
not
self
>
other
)],
(
'__le__'
,
lambda
self
,
other
:
not
self
>
other
)],
'__ge__'
:
[(
'__le__'
,
lambda
self
,
other
:
other
>=
self
),
'__ge__'
:
[(
'__le__'
,
lambda
self
,
other
:
(
not
self
>=
other
)
or
self
==
other
),
(
'__gt__'
,
lambda
self
,
other
:
not
other
>=
self
),
(
'__gt__'
,
lambda
self
,
other
:
self
>=
other
and
not
self
==
other
),
(
'__lt__'
,
lambda
self
,
other
:
not
self
>=
other
)]
(
'__lt__'
,
lambda
self
,
other
:
not
self
>=
other
)]
}
}
roots
=
set
(
dir
(
cls
))
&
set
(
convert
)
roots
=
set
(
dir
(
cls
))
&
set
(
convert
)
...
...
Lib/test/test_functools.py
Dosyayı görüntüle @
374274db
...
@@ -361,6 +361,8 @@ class TestTotalOrdering(unittest.TestCase):
...
@@ -361,6 +361,8 @@ class TestTotalOrdering(unittest.TestCase):
self
.
value
=
value
self
.
value
=
value
def
__lt__
(
self
,
other
):
def
__lt__
(
self
,
other
):
return
self
.
value
<
other
.
value
return
self
.
value
<
other
.
value
def
__eq__
(
self
,
other
):
return
self
.
value
==
other
.
value
self
.
assertTrue
(
A
(
1
)
<
A
(
2
))
self
.
assertTrue
(
A
(
1
)
<
A
(
2
))
self
.
assertTrue
(
A
(
2
)
>
A
(
1
))
self
.
assertTrue
(
A
(
2
)
>
A
(
1
))
self
.
assertTrue
(
A
(
1
)
<=
A
(
2
))
self
.
assertTrue
(
A
(
1
)
<=
A
(
2
))
...
@@ -375,6 +377,8 @@ class TestTotalOrdering(unittest.TestCase):
...
@@ -375,6 +377,8 @@ class TestTotalOrdering(unittest.TestCase):
self
.
value
=
value
self
.
value
=
value
def
__le__
(
self
,
other
):
def
__le__
(
self
,
other
):
return
self
.
value
<=
other
.
value
return
self
.
value
<=
other
.
value
def
__eq__
(
self
,
other
):
return
self
.
value
==
other
.
value
self
.
assertTrue
(
A
(
1
)
<
A
(
2
))
self
.
assertTrue
(
A
(
1
)
<
A
(
2
))
self
.
assertTrue
(
A
(
2
)
>
A
(
1
))
self
.
assertTrue
(
A
(
2
)
>
A
(
1
))
self
.
assertTrue
(
A
(
1
)
<=
A
(
2
))
self
.
assertTrue
(
A
(
1
)
<=
A
(
2
))
...
@@ -389,6 +393,8 @@ class TestTotalOrdering(unittest.TestCase):
...
@@ -389,6 +393,8 @@ class TestTotalOrdering(unittest.TestCase):
self
.
value
=
value
self
.
value
=
value
def
__gt__
(
self
,
other
):
def
__gt__
(
self
,
other
):
return
self
.
value
>
other
.
value
return
self
.
value
>
other
.
value
def
__eq__
(
self
,
other
):
return
self
.
value
==
other
.
value
self
.
assertTrue
(
A
(
1
)
<
A
(
2
))
self
.
assertTrue
(
A
(
1
)
<
A
(
2
))
self
.
assertTrue
(
A
(
2
)
>
A
(
1
))
self
.
assertTrue
(
A
(
2
)
>
A
(
1
))
self
.
assertTrue
(
A
(
1
)
<=
A
(
2
))
self
.
assertTrue
(
A
(
1
)
<=
A
(
2
))
...
@@ -403,6 +409,8 @@ class TestTotalOrdering(unittest.TestCase):
...
@@ -403,6 +409,8 @@ class TestTotalOrdering(unittest.TestCase):
self
.
value
=
value
self
.
value
=
value
def
__ge__
(
self
,
other
):
def
__ge__
(
self
,
other
):
return
self
.
value
>=
other
.
value
return
self
.
value
>=
other
.
value
def
__eq__
(
self
,
other
):
return
self
.
value
==
other
.
value
self
.
assertTrue
(
A
(
1
)
<
A
(
2
))
self
.
assertTrue
(
A
(
1
)
<
A
(
2
))
self
.
assertTrue
(
A
(
2
)
>
A
(
1
))
self
.
assertTrue
(
A
(
2
)
>
A
(
1
))
self
.
assertTrue
(
A
(
1
)
<=
A
(
2
))
self
.
assertTrue
(
A
(
1
)
<=
A
(
2
))
...
@@ -428,6 +436,22 @@ class TestTotalOrdering(unittest.TestCase):
...
@@ -428,6 +436,22 @@ class TestTotalOrdering(unittest.TestCase):
class
A
:
class
A
:
pass
pass
def
test_bug_10042
(
self
):
@functools.total_ordering
class
TestTO
:
def
__init__
(
self
,
value
):
self
.
value
=
value
def
__eq__
(
self
,
other
):
if
isinstance
(
other
,
TestTO
):
return
self
.
value
==
other
.
value
return
False
def
__lt__
(
self
,
other
):
if
isinstance
(
other
,
TestTO
):
return
self
.
value
<
other
.
value
raise
TypeError
with
self
.
assertRaises
(
TypeError
):
TestTO
(
8
)
<=
()
def
test_main
(
verbose
=
None
):
def
test_main
(
verbose
=
None
):
test_classes
=
(
test_classes
=
(
TestPartial
,
TestPartial
,
...
...
Misc/ACKS
Dosyayı görüntüle @
374274db
...
@@ -669,6 +669,7 @@ Bernhard Reiter
...
@@ -669,6 +669,7 @@ Bernhard Reiter
Steven Reiz
Steven Reiz
Roeland Rengelink
Roeland Rengelink
Tim Rice
Tim Rice
Francesco Ricciardi
Jan Pieter Riegel
Jan Pieter Riegel
Armin Rigo
Armin Rigo
Nicholas Riley
Nicholas Riley
...
...
Misc/NEWS
Dosyayı görüntüle @
374274db
...
@@ -43,6 +43,9 @@ Core and Builtins
...
@@ -43,6 +43,9 @@ Core and Builtins
Library
Library
-------
-------
- Issue #10042: Fixed the total_ordering decorator to handle cross-type
comparisons that could lead to infinite recursion.
- Issue #10979: unittest stdout buffering now works with class and module
- Issue #10979: unittest stdout buffering now works with class and module
setup and teardown.
setup and teardown.
...
...
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