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
f673f0c4
Kaydet (Commit)
f673f0c4
authored
Mar 13, 2010
tarafından
Mark Dickinson
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #7845: Make 1j.__le__(2j) return NotImplemented rather than raising TypeError.
üst
ad0ef571
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
24 additions
and
11 deletions
+24
-11
stdtypes.rst
Doc/library/stdtypes.rst
+3
-2
test_complex.py
Lib/test/test_complex.py
+14
-5
NEWS
Misc/NEWS
+5
-0
complexobject.c
Objects/complexobject.c
+2
-4
No files found.
Doc/library/stdtypes.rst
Dosyayı görüntüle @
f673f0c4
...
...
@@ -168,8 +168,9 @@ Objects of different types, except different numeric types, never compare equal.
Furthermore, some types (for example, function objects) support only a degenerate
notion of comparison where any two objects of that type are unequal. The ``<``,
``<=``, ``>`` and ``>=`` operators will raise a :exc:`TypeError` exception when
any operand is a complex number, the objects are of different types that cannot
be compared, or other cases where there is no defined ordering.
comparing a complex number with another built-in numeric type, when the objects
are of different types that cannot be compared, or in other cases where there is
no defined ordering.
.. index::
single: __eq__() (instance method)
...
...
Lib/test/test_complex.py
Dosyayı görüntüle @
f673f0c4
...
...
@@ -3,6 +3,7 @@ from test import support
from
random
import
random
from
math
import
atan2
,
isnan
,
copysign
import
operator
INF
=
float
(
"inf"
)
NAN
=
float
(
"nan"
)
...
...
@@ -110,15 +111,23 @@ class ComplexTest(unittest.TestCase):
def
test_richcompare
(
self
):
self
.
assertRaises
(
OverflowError
,
complex
.
__eq__
,
1
+
1
j
,
1
<<
10000
)
self
.
assert
Equal
(
complex
.
__lt__
(
1
+
1
j
,
None
),
NotImplemented
)
self
.
assert
Is
(
complex
.
__lt__
(
1
+
1
j
,
None
),
NotImplemented
)
self
.
assertIs
(
complex
.
__eq__
(
1
+
1
j
,
1
+
1
j
),
True
)
self
.
assertIs
(
complex
.
__eq__
(
1
+
1
j
,
2
+
2
j
),
False
)
self
.
assertIs
(
complex
.
__ne__
(
1
+
1
j
,
1
+
1
j
),
False
)
self
.
assertIs
(
complex
.
__ne__
(
1
+
1
j
,
2
+
2
j
),
True
)
self
.
assertRaises
(
TypeError
,
complex
.
__lt__
,
1
+
1
j
,
2
+
2
j
)
self
.
assertRaises
(
TypeError
,
complex
.
__le__
,
1
+
1
j
,
2
+
2
j
)
self
.
assertRaises
(
TypeError
,
complex
.
__gt__
,
1
+
1
j
,
2
+
2
j
)
self
.
assertRaises
(
TypeError
,
complex
.
__ge__
,
1
+
1
j
,
2
+
2
j
)
self
.
assertIs
(
complex
.
__lt__
(
1
+
1
j
,
2
+
2
j
),
NotImplemented
)
self
.
assertIs
(
complex
.
__le__
(
1
+
1
j
,
2
+
2
j
),
NotImplemented
)
self
.
assertIs
(
complex
.
__gt__
(
1
+
1
j
,
2
+
2
j
),
NotImplemented
)
self
.
assertIs
(
complex
.
__ge__
(
1
+
1
j
,
2
+
2
j
),
NotImplemented
)
self
.
assertRaises
(
TypeError
,
operator
.
lt
,
1
+
1
j
,
2
+
2
j
)
self
.
assertRaises
(
TypeError
,
operator
.
le
,
1
+
1
j
,
2
+
2
j
)
self
.
assertRaises
(
TypeError
,
operator
.
gt
,
1
+
1
j
,
2
+
2
j
)
self
.
assertRaises
(
TypeError
,
operator
.
ge
,
1
+
1
j
,
2
+
2
j
)
self
.
assertIs
(
operator
.
eq
(
1
+
1
j
,
1
+
1
j
),
True
)
self
.
assertIs
(
operator
.
eq
(
1
+
1
j
,
2
+
2
j
),
False
)
self
.
assertIs
(
operator
.
ne
(
1
+
1
j
,
1
+
1
j
),
False
)
self
.
assertIs
(
operator
.
ne
(
1
+
1
j
,
2
+
2
j
),
True
)
def
test_mod
(
self
):
# % is no longer supported on complex numbers
...
...
Misc/NEWS
Dosyayı görüntüle @
f673f0c4
...
...
@@ -12,6 +12,11 @@ What's New in Python 3.2 Alpha 1?
Core and Builtins
-----------------
- Issue #7845: Rich comparison methods on the complex type now return
NotImplemented rather than raising a TypeError when comparing with an
incompatible type; this allows user-defined classes to implement their own
comparisons with complex.
- Issue #3137: Don't ignore errors at startup, especially a keyboard interrupt
(SIGINT). If an error occurs while importing the site module, the error is
printed and Python exits. Initialize the GIL before importing the site
...
...
Objects/complexobject.c
Dosyayı görüntüle @
f673f0c4
...
...
@@ -625,10 +625,8 @@ complex_richcompare(PyObject *v, PyObject *w, int op)
TO_COMPLEX
(
w
,
j
);
if
(
op
!=
Py_EQ
&&
op
!=
Py_NE
)
{
/* XXX Should eventually return NotImplemented */
PyErr_SetString
(
PyExc_TypeError
,
"no ordering relation is defined for complex numbers"
);
return
NULL
;
Py_INCREF
(
Py_NotImplemented
);
return
Py_NotImplemented
;
}
if
((
i
.
real
==
j
.
real
&&
i
.
imag
==
j
.
imag
)
==
(
op
==
Py_EQ
))
...
...
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