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 _______________________________________________ Python-3000 mailing list Python-3000@python.org http://mail.python.org/mailman/listinfo/python-3000 Unsubscribe: http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com