On Thu, Jun 12, 2008 at 8:24 AM, Armin Rigo <[EMAIL PROTECTED]> 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/)
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to