[Python-Dev] The interpreter accepts f(**{'5':'foo'}); is this intentional? (original) (raw)
Terry Reedy tjreedy at udel.edu
Thu Feb 5 22:13:36 CET 2009
- Previous message: [Python-Dev] The interpreter accepts f(**{'5':'foo'}); is this intentional?
- Next message: [Python-Dev] The interpreter accepts f(**{'5':'foo'}); is this intentional?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Christian Heimes wrote:
Nick Coghlan wrote:
Generally speaking, Python namespace dictionaries (be it globals(), locals(), the dict attribute of an instance or a set of keyword arguments) aren't required to enforce the use of legal identifiers (in many cases, the CPython variants don't even enforce the use of strings). Side note: CPython's dict code has a special case for str objects (PyStringObject in 2.x, PyUnicodeObject in 3.x). The internal lookup method is optimized for str objects. Python uses dict objects for all its namespaces like classes, modules and most objects, so dict with str as keys are pretty common. 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.
lookdict() still fast but not as fast as lookdictstring(). It doesn't make a huge difference but you should still keep the fact in your head.
We could abuse the state of the malookup function pointer to check the dict for str only keys. But it would break for unicode keys thus making from future import unicodeliterals useless.
Assuming that 3.x dicts are optimized for the 3.x string type, this is not a problem for 3.x ;-).
tjr
- Previous message: [Python-Dev] The interpreter accepts f(**{'5':'foo'}); is this intentional?
- Next message: [Python-Dev] The interpreter accepts f(**{'5':'foo'}); is this intentional?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]