[Python-Dev] _length_cue()
Armin Rigo
arigo at tunes.org
Thu Feb 9 00:51:56 CET 2006
Hi Raymond,
On Wed, Feb 08, 2006 at 03:02:21PM -0500, Raymond Hettinger wrote:
> IMHO, the "safety reasons" are imaginary -- the scenario would involve
> subclassing one of these builtin objects and attaching an identically named
> private method.
No, the senario applies to any user-defined iterator class, not
necessary subclassing an existing one:
>>> class MyIter(object):
... def __iter__(self):
... return self
... def next(self):
... return whatever
... def _length_cue(self):
... print "oups! please, CPython, don't call me unexpectedly"
...
>>> list(MyIter())
oups! please, CPython, don't call me unexpectedly
(...)
This means that _length_cue() is at the moment a special method, in the
sense that Python can invoke it implicitely.
This said, do we vote for __length_hint__ or __length_cue__? :-)
And does anyone objects about __getitem_hint__ or __getitem_cue__?
Maybe __lookahead_hint__ or __lookahead_cue__?
Armin
More information about the Python-Dev
mailing list