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.
  • Loading branch information
tseaver committed Mar 21, 2013
1 parent 92677d6 commit 7b5c5fd
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Changelog
4.0.1 (unreleased)
------------------

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


4.0 (2013-02-24)
----------------
Expand Down
1 change: 1 addition & 0 deletions src/Acquisition/_Acquisition.c
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,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 @@ -2414,6 +2414,24 @@ def test_unwrapped_implicit_acquirer_unwraps__parent__():
True
"""

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 7b5c5fd

Please sign in to comment.