[Python-3000] PEP: rename it.next() to it.next(), add a next() built-in (original) (raw)
Ka-Ping Yee python at zesty.ca
Tue Mar 6 03:28:04 CET 2007
- Previous message: [Python-3000] PEP: rename it.next() to it.__next__(), add a next() built-in
- Next message: [Python-3000] PEP: rename it.next() to it.__next__(), add a next() built-in
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Previous message: [Python-3000] PEP: rename it.next() to it.__next__(), add a next() built-in
- Next message: [Python-3000] PEP: rename it.next() to it.__next__(), add a next() built-in
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]