[pypy-issue] Issue #2277: zip doesn't call __iter__ on list objects (pypy/pypy)

Iain Buclaw issues-reply at bitbucket.org
Wed Apr 20 10:58:13 EDT 2016


New issue 2277: zip doesn't call __iter__ on list objects
https://bitbucket.org/pypy/pypy/issues/2277/zip-doesnt-call-__iter__-on-list-objects

Iain Buclaw:


```
#!python

class A(object):
    def __init__(self, values):
        self.values = values

    def __iter__(self):
        print "DEBUG: (A) __iter__ called"
        return list.__iter__(self.values)

class B(list):
    def __init__(self, values):
        list.__init__(self, values)

    def __iter__(self):
        print "DEBUG: (B) __iter__ called"
        return list.__iter__(self)

mylist = [1,2,3,4]

a = A(mylist)
b = B(mylist)

c = zip(a, mylist)
d = zip(b, mylist)
```

When running this test program, I get two results:
```
# python bin/test.py 
DEBUG: (A) __iter__ called
DEBUG: (B) __iter__ called

# pypy bin/test.py 
DEBUG: (A) __iter__ called
```
Using pypy 2.7.10 and python 2.7.6.






More information about the pypy-issue mailing list