A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2009-February/085895.html below:

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

[Python-Dev] The interpreter accepts f(**{'5':'foo'}); is this intentional? [Python-Dev] The interpreter accepts f(**{'5':'foo'}); is this intentional?Christian Heimes lists at cheimes.de
Thu Feb 5 22:04:18 CET 2009
Guido van Rossum schrieb:
> I'd prefer a compromise -- the keys should be strings, but should not
> be required to be valid identifiers. All Python implementations should
> support this. Rationale: a type check is cheap, and using strings
> exclusively makes the use of a faster dict implementation possible. A
> check for a conforming identifier is relatively expensive and serves
> no purpose except being pedantic.

As pointed out in my other posting, an additional type check isn't
required in most cases. A C function that checks ma_lookup does the same
trick.

int
PyDict_StringKeysOnly(PyObject *dict) {
    if (((PyDictObject*)dict)->ma_lookup == lookdict_string)
        return 1;
    else {
        /* check all keys for PyStringObject */
    }
}

The performance penalty is slime to nothing for the common case.

How are we going to handle str subclasses and unicode? Should we allow
all subclasses of basestring? Or just str and unicode? Or str only?

Christian
More information about the Python-Dev mailing list

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