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 lookdict_string(). It doesn't make a huge difference but you > should still keep the fact in your head. > > We could abuse the state of the ma_lookup function pointer to check the > dict for str only keys. But it would break for unicode keys thus making > from __future__ import unicode_literals useless. Assuming that 3.x dicts are optimized for the 3.x string type, this is not a problem for 3.x ;-). tjr
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4