[Python-Dev] bug or a feature?

Scott Dial scott+python-dev at scottdial.com
Wed Jun 11 21:23:38 CEST 2008


Phillip J. Eby wrote:
> That test is there to ensure that it interoperates with code using the 
> AddOns library from the Cheeseshop; SQLAlchemy is not the source of the 
> usage.

Now that's interesting. The AddOns library uses class objects as keys in 
the __dict__, but that doesn't says anything about the usage of 
locals(). At no point in the AddOns library is locals() abused like 
this, so even if one asserts that assignment to the dict returned by 
locals() is a bug, the underlying behavior of interest is whether 
__dict__ is allowed to have non-string keys.

 >>> from peak.util.addons import AddOn
 >>> class C: pass
 >>> class A(AddOn): pass
 >>> spam = C()
 >>> print spam.__dict__
{}
 >>> A(spam)
 >>> print spam.__dict__
{<class 'A'>: <A object at ...>}

If non-string keys are not allowed in __dict__, then the AddOns library 
should be changed to add another dict to the object of interest to track 
these AddOn instances.

-Scott

-- 
Scott Dial
scott at scottdial.com
scodial at cs.indiana.edu


More information about the Python-Dev mailing list