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
271a8689
Kaydet (Commit)
271a8689
authored
Agu 15, 2006
tarafından
Neal Norwitz
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Subclasses of int/long are allowed to define an __index__.
üst
6e482569
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
12 deletions
+11
-12
test_index.py
Lib/test/test_index.py
+9
-8
abstract.c
Objects/abstract.c
+2
-4
No files found.
Lib/test/test_index.py
Dosyayı görüntüle @
271a8689
...
@@ -48,11 +48,12 @@ class BaseTestCase(unittest.TestCase):
...
@@ -48,11 +48,12 @@ class BaseTestCase(unittest.TestCase):
self
.
assertEqual
(
self
.
o
.
__index__
(),
4
)
self
.
assertEqual
(
self
.
o
.
__index__
(),
4
)
self
.
assertEqual
(
self
.
n
.
__index__
(),
5
)
self
.
assertEqual
(
self
.
n
.
__index__
(),
5
)
def
test_infinite_recursion
(
self
):
def
test_subclasses
(
self
):
self
.
failUnlessRaises
(
TypeError
,
operator
.
index
,
TrapInt
())
r
=
range
(
10
)
self
.
failUnlessRaises
(
TypeError
,
operator
.
index
,
TrapLong
())
self
.
assertEqual
(
r
[
TrapInt
(
5
):
TrapInt
(
10
)],
r
[
5
:
10
])
self
.
failUnless
(
slice
(
TrapInt
())
.
indices
(
0
)
==
(
0
,
0
,
1
))
self
.
assertEqual
(
r
[
TrapLong
(
5
):
TrapLong
(
10
)],
r
[
5
:
10
])
self
.
failUnlessRaises
(
TypeError
,
slice
(
TrapLong
())
.
indices
,
0
)
self
.
assertEqual
(
slice
(
TrapInt
())
.
indices
(
0
),
(
0
,
0
,
1
))
self
.
assertEqual
(
slice
(
TrapLong
(
0
))
.
indices
(
0
),
(
0
,
0
,
1
))
def
test_error
(
self
):
def
test_error
(
self
):
self
.
o
.
ind
=
'dumb'
self
.
o
.
ind
=
'dumb'
...
@@ -104,9 +105,9 @@ class SeqTestCase(unittest.TestCase):
...
@@ -104,9 +105,9 @@ class SeqTestCase(unittest.TestCase):
self
.
assertEqual
(
self
.
seq
.
__mul__
(
self
.
n
),
self
.
seq
*
5
)
self
.
assertEqual
(
self
.
seq
.
__mul__
(
self
.
n
),
self
.
seq
*
5
)
self
.
assertEqual
(
self
.
seq
.
__rmul__
(
self
.
n
),
self
.
seq
*
5
)
self
.
assertEqual
(
self
.
seq
.
__rmul__
(
self
.
n
),
self
.
seq
*
5
)
def
test_
infinite_recursion
(
self
):
def
test_
subclasses
(
self
):
self
.
failUnlessRaises
(
TypeError
,
operator
.
getitem
,
self
.
seq
,
TrapInt
()
)
self
.
assertEqual
(
self
.
seq
[
TrapInt
()],
self
.
seq
[
0
]
)
self
.
failUnlessRaises
(
TypeError
,
operator
.
getitem
,
self
.
seq
,
TrapLong
()
)
self
.
assertEqual
(
self
.
seq
[
TrapLong
()],
self
.
seq
[
0
]
)
def
test_error
(
self
):
def
test_error
(
self
):
self
.
o
.
ind
=
'dumb'
self
.
o
.
ind
=
'dumb'
...
...
Objects/abstract.c
Dosyayı görüntüle @
271a8689
...
@@ -945,16 +945,14 @@ PyNumber_Index(PyObject *item)
...
@@ -945,16 +945,14 @@ PyNumber_Index(PyObject *item)
PyObject
*
result
=
NULL
;
PyObject
*
result
=
NULL
;
if
(
item
==
NULL
)
if
(
item
==
NULL
)
return
null_error
();
return
null_error
();
/* XXX(nnorwitz): should these be CheckExact? Aren't subclasses ok? */
if
(
PyInt_Check
(
item
)
||
PyLong_Check
(
item
))
{
if
(
PyInt_CheckExact
(
item
)
||
PyLong_CheckExact
(
item
))
{
Py_INCREF
(
item
);
Py_INCREF
(
item
);
return
item
;
return
item
;
}
}
if
(
PyIndex_Check
(
item
))
{
if
(
PyIndex_Check
(
item
))
{
result
=
item
->
ob_type
->
tp_as_number
->
nb_index
(
item
);
result
=
item
->
ob_type
->
tp_as_number
->
nb_index
(
item
);
/* XXX(nnorwitz): Aren't subclasses ok here too? */
if
(
result
&&
if
(
result
&&
!
PyInt_Check
Exact
(
result
)
&&
!
PyLong_CheckExact
(
result
))
{
!
PyInt_Check
(
result
)
&&
!
PyLong_Check
(
result
))
{
PyErr_Format
(
PyExc_TypeError
,
PyErr_Format
(
PyExc_TypeError
,
"__index__ returned non-(int,long) "
\
"__index__ returned non-(int,long) "
\
"(type %.200s)"
,
"(type %.200s)"
,
...
...
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