Ionel Cristian Mărieș added the comment: On Sat, Apr 18, 2015 at 7:23 PM, Ethan Furman <rep...@bugs.python.org> wrote:
> > class GenericProxy: > def __init__(self, proxied): > self.proxied = proxied > # in case proxied is an __iter__ iterator > @property > def __iter__(self): > if not hasattr(self.proxied, '__iter__'): > raise AttributeError > else: > return self > @property > def __next__(self): > if not hasattr(self.proxied, '__next__'): > raise AttributeError > else: > return next(self.proxied) Unfortunately your implementation is incorrect as you forgot to that the property needs to return a function. This is a correct implementation that works as expected (in the sense that *iter does in fact honor the descriptor protocol)*: class GenericProxy: > def __init__(self, proxied): > self.proxied = proxied > # in case proxied is an __iter__ iterator > @property > def __iter__(self): > if not hasattr(self.proxied, '__iter__'): > raise AttributeError > else: > return *lambda:* self > @property > def __next__(self): > if not hasattr(self.proxied, '__next__'): > raise AttributeError > else: > return *lambda: *next(self.proxied) > The iter machinery doesn't "grab values and call them", you've misinterpreted the error. Thanks, -- Ionel Cristian Mărieș, http://blog.ionelmc.ro ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue23990> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com