Skip to content

Commit

Permalink
Don't raise AttributeError for '__iter__' if fallback to '__getitem__…
Browse files Browse the repository at this point in the history
…' succeeds.

LP #1155760.

Cherry-pick 7b5c5fd from master.
  • Loading branch information
tseaver committed Feb 17, 2015
1 parent 87ae517 commit e525342
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Changelog
=========

2.13.9 (unreleased)
-------------------

- Don't raise an attribute error for ``__iter__`` if the fallback to
``__getitem__`` succeeds. LP #1155760.

2.13.8 (2011-06-11)
-------------------

Expand Down
1 change: 1 addition & 0 deletions src/Acquisition/_Acquisition.c
Original file line number Diff line number Diff line change
Expand Up @@ -984,6 +984,7 @@ Wrapper_iter(Wrapper *self)
res = NULL;
}
} else if (PySequence_Check(obj)) {
PyErr_Clear();
ASSIGN(res,PySeqIter_New(OBJECT(self)));
} else {
res = PyErr_Format(PyExc_TypeError, "iteration over non-sequence");
Expand Down
18 changes: 18 additions & 0 deletions src/Acquisition/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2397,6 +2397,24 @@ def test___parent__aq_parent_circles():
"""


def test__iter__after_AttributeError():
""" See https://bugs.launchpad.net/zope2/+bug/1155760
>>> from Acquisition import Implicit
>>> class C(Implicit):
... l = [0, 1, 2, 3, 4]
... def __getitem__(self, i):
... return self.l[i]
>>> a = C()
>>> b = C().__of__(a)
>>> import time
>>> try:
... for n in b:
... t = time.gmtime()
... except AttributeError:
... raise
"""

import unittest
from doctest import DocTestSuite, DocFileSuite

Expand Down

0 comments on commit e525342

Please sign in to comment.