[Python-Dev] Non-string keys in namespace dicts

Phillip J. Eby pje at telecommunity.com
Tue Dec 4 07:20:32 CET 2007

At 10:17 PM 12/3/2007 -0700, Neil Toronto wrote:
>Phillip J. Eby wrote:
> > Actually, you're missing the part where such evil code *can't* muck
> > things up for class dictionaries.  Type dicts aren't reachable via
> > ordinary Python code; you *have* to modify them via setattr.  (The
> > __dict__ of types returns a read-only proxy object, so the most evil
> > rich compare you can imagine still can't touch it.)
>Interesting. But I'm going to have to say it probably wouldn't work as
>well, since C code can and does alter tp_dict directly. Those places in
>the core would have to be altered to invalidate the cache.

Eh?  Where is the type dictionary altered outside of setattr and 
class creation?

>  There's also
>the issue of extensions, which so far have been able to alter any
>tp_dict without problems.

Do you have any actual examples?

Believe me, I'm the last person to suggest removing useful hack, er, 
hooks.  :)  But I don't think that type __dict__ munging is actually 
common at all.

>It'd also be really annoying for a class to
>have to notify all of its subclasses when one of its attributes changed.

It's not all subclasses - only those subclasses that don't shadow the 
attribute.  Also, it's not necessarily the case that notification 
would be O(subclasses) - it could be done via a version counter, as 
in your approach.  Admittedly, that would require an extra bit of 
indirection, since you'd need to keep (and check) counters for each descriptor.

More information about the Python-Dev mailing list