short path evaluation, why is f() called here: dict(a=1).get('a', f())

Steven D'Aprano steven at
Tue Jan 15 04:14:19 CET 2008

On Mon, 14 Jan 2008 15:15:28 -0800, Paul Rubin wrote:

> Steven D'Aprano <steve at> writes:
>> map = {'a': Aclass, 'b': Bclass, 'c': Cclass} class_ = map.get(astring,
>> default=Zclass)
>> The result I want is the class, not the result of calling the class
>> (which would be an instance). If I wanted the other semantics, I'd be
>> using defaultdict instead.
> I used default as a keyward arg name indicating the presence of a
> callable.  I probably should have called it defaultfunc or something.
> x = d.get('a', f)      # --> default value is f x = d.get('a',
> defaultfunc=f)  # --> default value is result of f() .

So you're talking about proposed *added* behaviour, rather than 
*replacing* the current behaviour?

Sorry if I misunderstood you in the first place.


More information about the Python-list mailing list