[Python-Dev] _length_cue() (original) (raw)

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