mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
Subclasses of int/long are allowed to define an __index__.
This commit is contained in:
parent
6e482569c8
commit
271a8689e9
2 changed files with 11 additions and 12 deletions
|
@ -945,16 +945,14 @@ PyNumber_Index(PyObject *item)
|
|||
PyObject *result = NULL;
|
||||
if (item == NULL)
|
||||
return null_error();
|
||||
/* XXX(nnorwitz): should these be CheckExact? Aren't subclasses ok? */
|
||||
if (PyInt_CheckExact(item) || PyLong_CheckExact(item)) {
|
||||
if (PyInt_Check(item) || PyLong_Check(item)) {
|
||||
Py_INCREF(item);
|
||||
return item;
|
||||
}
|
||||
if (PyIndex_Check(item)) {
|
||||
result = item->ob_type->tp_as_number->nb_index(item);
|
||||
/* XXX(nnorwitz): Aren't subclasses ok here too? */
|
||||
if (result &&
|
||||
!PyInt_CheckExact(result) && !PyLong_CheckExact(result)) {
|
||||
!PyInt_Check(result) && !PyLong_Check(result)) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"__index__ returned non-(int,long) " \
|
||||
"(type %.200s)",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue