[Python-Dev] The interpreter accepts f(**{'5':'foo'}); is this intentional?

Christian Heimes lists at cheimes.de
Thu Feb 5 22:55:24 CET 2009


Terry Reedy schrieb:
>> The first time a non str object is inserted or looked up, the dict
>> swiches to a more general lookup methods.
> 
> This makes adding a string-only dict pretty trivial, if desired.

It's not as trivial as it seems. The switch over to the general lookup
method happens when a non str object is *looked up*.

d = {'a': None} # uses lookdict_string()
d.get(1, None) # d now uses lookdict()

"d->ma_lookup == lookdict_string" is a sufficient condition, not a
condicio sine qua non.

> Assuming that 3.x dicts are optimized for the 3.x string type, this is
> not a problem for 3.x ;-).

Well, it's always optimized for the str type - which happens to be
PyUnicodeObject in 3.x.

Christian


More information about the Python-Dev mailing list