[Python-3000] PEP: rename it.next() to it.__next__(), add a next() built-in

Ka-Ping Yee python at zesty.ca
Tue Mar 6 03:28:04 CET 2007


On Tue, 6 Mar 2007, Neil Schemenauer wrote:
> The argument that all "protocol" methods should have double
> underscore names seems to be pretty weak too.  It's only an appeal
> for consistency, I think.  We don't suggest that file-like objects
> should implement __read__() instead of read(), for example.

There is a convention and it is applied quite consistently:

    Double-underscores are for methods implicitly invoked
    by a language construct.

In fact, your example was specifically anticipated and addressed in
the PEP draft I posted here.  file.read() is not invoked by a language
construct.  When file.read() gets called, it is because the calling
code has an explicit call to read() in it, not because the standard
semantics of some piece of Python syntax require it to be invoked.

Not so for __getitem__, __add__, __iter__, etc. and also __next__.

This distinction is important because the "magical" invocation is
what makes name collisions more dangerous and confusing to debug.


-- ?!ng


More information about the Python-3000 mailing list