[Python-Dev] bug or a feature?

Armin Rigo arigo at tunes.org
Thu Jun 12 17:24:43 CEST 2008


On Wed, Jun 11, 2008 at 10:44:17PM -0400, Scott Dial wrote:
> The only reason the test used locals() was
> because it was the only way to insert a non-string key into the class
> namespace.

This discussion is mistakenly focused on locals().  There is a direct
way to have arbitrary keys in the dict of a type:

>>> MyClass = type('MyClass', (Base,), {42: 64})
>>> MyClass.__dict__[42]

There is, however, no way to modify or add non-string keys in the type
after its creation.  So the question is whether the type() constructor
is allowed to fail with a TypeError when the initial dict contains
non-string keys (this is PyPy's current behavior).

A bientot,


More information about the Python-Dev mailing list