[Python-Dev] Re: Re: PEP 267 improvement idea (original) (raw)

Samuele Pedroni pedronis@bluewin.ch
Tue, 14 Jan 2003 20:14:12 +0100


From: "Terry Reedy" <tjreedy@udel.edu>

> overhead pays when it's used as a namespace. Both "lookdictnamespace" > and "lookdictstring" will fall back to a "lookdict" dictionary when a > non-string key is inserted.

Until reading this sentence, I had never thought of doing something so bizarre as adding a non-string key to a namespace (via the 'backdoor' .dict reference). But it currently works. >>> import main >>> main.dict[1]='x' >>> dir() [1, 'builtins', 'doc', 'main', 'name', 'x'] However, since the implementation of namespaces is an implementation detail, and since I can (as yet) see no need for the above (except to astound and amaze), I think you (and Guido) should feel free to disallow this, especially if doing so facilitates speed improvements.

I may add that Jython already does that, and gets away with it wihout much ado

Jython 2.1 on java1.3.0 (JIT: null) Type "copyright", "credits" or "license" for more information.

import main main.dict[1]=2 Traceback (innermost last): File "", line 1, in ? TypeError: keys in namespace must be strings

same for class and instances dicts.