[Python-Dev] bug or a feature?
Guido van Rossum
guido at python.org
Thu Jun 12 21:46:18 CEST 2008
On Thu, Jun 12, 2008 at 8:24 AM, Armin Rigo <arigo at tunes.org> wrote:
> 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]
> 64
>
> 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).
The intention was for these dicts to be used as namespaces. I think of
it as follows:
(a) Using non-string keys is a no-no, but the implementation isn't
required to go out of its way to forbid it.
(b) Using non-empty string keys that aren't well-formed identifiers
should be allowed.
--
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-Dev
mailing list