[Python-Dev] bug or a feature?

Phillip J. Eby pje at telecommunity.com
Thu Jun 12 12:01:18 CEST 2008

At 08:32 PM 6/11/2008 -0400, Terry Reedy wrote:
>The Data Model chapter of the Reference Manual lists .__dict__ as a special
>attribute of callables, modules, classes, and instances.  It describes
>__dict__ as a "namespace dictionary" or "implementation of the namespace"
>thereof.  Since namespaces map names (or possibly non-name strings) to
>objects, this to me implies that an implementation is and should not be
>required to allow non-strings in __dict__.
>The same chapter has more than one sentence saying something like "o.x is
>equivalent to o.__dict__['x']".  While one could read this as prohibiting
>o.__dict__[non_string], one could also read it as being silent, neither
>allowing nor prohibiting.

As it happens, most objects' __dict__ slots are settable by default, 
and *require* that you set it to a dict or subclass thereof.  This 
seems (to me) to imply that a standard dictionary (i.e. one 
supporting keys of any type) is required.  (In the sense that a dict 
subclass which rejects non-strings would be violating the Liskov principle.)

More information about the Python-Dev mailing list