[Python-Dev] defaultdict and on_missing()

Walter Dörwald walter at livinglogic.de
Thu Feb 23 22:55:40 CET 2006

Guido van Rossum wrote:

> On 2/22/06, Michael Chermside <mcherm at mcherm.com> wrote:
>> A minor related point about on_missing():
>> Haven't we learned from regrets over the .next() method of iterators
>> that all "magically" invoked methods should be named using the __xxx__
>> pattern? Shouldn't it be named __on_missing__() instead?
> Good point. I'll call it __missing__. I've uploaded a new patch to
> python.org/sf/1433928.

I always thought that __magic__ method calls are done by Python on 
objects it doesn't know about. The special method name ensures that it 
is indeed the protocol Python is talking about, not some random method 
(with next() being the exception). In the defaultdict case this isn't a 
problem, because defaultdict is calling its own method.

    Walter Dörwald

More information about the Python-Dev mailing list