The following demonstrates the source of the problem:
from __future__ import print_function
class TestList(list):
def __iter__(self): yield 1 yield 2 yield 3
if __name__ == '__main__': x = TestList()
x.extend([4, 5, 6]) print(repr(tuple(x))) print(repr(list(x)))
Basically it looks like in CPython there's a special case for calling tuple on a list which bypasses all the normal methods.
The following demonstrates the source of the problem:
from __future__ import print_function
class TestList(list):
def __iter__(self):
yield 1
yield 2
yield 3
if __name__ == '__main__':
x = TestList()
x.extend([4, 5, 6]) repr(tuple( x))) repr(list( x)))
print(
print(
Basically it looks like in CPython there's a special case for calling tuple on a list which bypasses all the normal methods.