Message241425
On Sat, Apr 18, 2015 at 7:23 PM, Ethan Furman <report@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 |
|
Date |
User |
Action |
Args |
2015-04-18 16:44:54 | ionelmc | set | recipients:
+ ionelmc, terry.reedy, belopolsky, christian.heimes, Claudiu.Popa, ethan.furman, llllllllll, jedwards |
2015-04-18 16:44:53 | ionelmc | link | issue23990 messages |
2015-04-18 16:44:53 | ionelmc | create | |
|