Change filtertuple() to use tp_as_sequence->sq_item
instead of PyTuple_GetItem, so an overwritten __getitem__ in a tuple subclass works. SF bug #665835.
This commit is contained in:
parent
8d326b8581
commit
8dd19321bb
@ -419,7 +419,6 @@ class BuiltinTest(unittest.TestCase):
|
|||||||
def test_filter_subclasses(self):
|
def test_filter_subclasses(self):
|
||||||
# test, that filter() never returns tuple, str or unicode subclasses
|
# test, that filter() never returns tuple, str or unicode subclasses
|
||||||
# and that the result always go's through __getitem__
|
# and that the result always go's through __getitem__
|
||||||
# FIXME: For tuple currently it doesn't go through __getitem__
|
|
||||||
funcs = (None, lambda x: True)
|
funcs = (None, lambda x: True)
|
||||||
class tuple2(tuple):
|
class tuple2(tuple):
|
||||||
def __getitem__(self, index):
|
def __getitem__(self, index):
|
||||||
@ -428,7 +427,7 @@ class BuiltinTest(unittest.TestCase):
|
|||||||
def __getitem__(self, index):
|
def __getitem__(self, index):
|
||||||
return 2*str.__getitem__(self, index)
|
return 2*str.__getitem__(self, index)
|
||||||
inputs = {
|
inputs = {
|
||||||
tuple2: {(): (), (1, 2, 3): (1, 2, 3)}, # FIXME
|
tuple2: {(): (), (1, 2, 3): (2, 4, 6)},
|
||||||
str2: {"": "", "123": "112233"}
|
str2: {"": "", "123": "112233"}
|
||||||
}
|
}
|
||||||
if have_unicode:
|
if have_unicode:
|
||||||
|
@ -1888,8 +1888,13 @@ filtertuple(PyObject *func, PyObject *tuple)
|
|||||||
PyObject *item, *good;
|
PyObject *item, *good;
|
||||||
int ok;
|
int ok;
|
||||||
|
|
||||||
if ((item = PyTuple_GetItem(tuple, i)) == NULL)
|
if (tuple->ob_type->tp_as_sequence &&
|
||||||
|
tuple->ob_type->tp_as_sequence->sq_item) {
|
||||||
|
item = tuple->ob_type->tp_as_sequence->sq_item(tuple, i);
|
||||||
|
} else {
|
||||||
|
PyErr_SetString(PyExc_TypeError, "unsubscriptable object");
|
||||||
goto Fail_1;
|
goto Fail_1;
|
||||||
|
}
|
||||||
if (func == Py_None) {
|
if (func == Py_None) {
|
||||||
Py_INCREF(item);
|
Py_INCREF(item);
|
||||||
good = item;
|
good = item;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user