Commit 7b5c5fd1 authored by Tres Seaver's avatar Tres Seaver

Don't raise AttributeError for '__iter__' if fallback to '__getitem__' succeeds.

LP #1155760.
parent 92677d60
...@@ -4,6 +4,9 @@ Changelog ...@@ -4,6 +4,9 @@ Changelog
4.0.1 (unreleased) 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) 4.0 (2013-02-24)
---------------- ----------------
......
...@@ -994,6 +994,7 @@ Wrapper_iter(Wrapper *self) ...@@ -994,6 +994,7 @@ Wrapper_iter(Wrapper *self)
res = NULL; res = NULL;
} }
} else if (PySequence_Check(obj)) { } else if (PySequence_Check(obj)) {
PyErr_Clear();
ASSIGN(res,PySeqIter_New(OBJECT(self))); ASSIGN(res,PySeqIter_New(OBJECT(self)));
} else { } else {
res = PyErr_Format(PyExc_TypeError, "iteration over non-sequence"); res = PyErr_Format(PyExc_TypeError, "iteration over non-sequence");
......
...@@ -2414,6 +2414,24 @@ def test_unwrapped_implicit_acquirer_unwraps__parent__(): ...@@ -2414,6 +2414,24 @@ def test_unwrapped_implicit_acquirer_unwraps__parent__():
True 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 import unittest
from doctest import DocTestSuite, DocFileSuite from doctest import DocTestSuite, DocFileSuite
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment