protocols, inheritance and polymorphism

Steven Bethard steven.bethard at gmail.com
Tue Nov 23 20:59:31 CET 2004


Donn Cave wrote:
> Steven Bethard wrote:
> ...
>>The point here is that I'm using isinstance here because I *know* there 
>>are objects out there that, unlike Bunch objects, may have 'attributes' 
>>not stored in their __dict__, and I *know* they might get passed to 
>>Bunch.update.  Since I can't appropriately support their use, I want the 
>>user to be notified of this (with the TypeError).
>>
[snip]
> 
> I don't really see that isinstance() was necessary in principle
> here.  Not that it makes any difference to me, but it looks like
> you created this problem by defining these semantics in Bunch
> but failing to assign any identifiable attribute

Yup.  The reason I "needed" isinstance was that my implementation works 
directly with __dict__ instead of creating some __dict__-like attribute 
and writing the appropriate code in __getattr__ and __setattr__ to use 
this __dict__-like attribute instead.  I actually thought about using a 
__dict__-like attribute instead of __dict__ for exactly this reason (so 
that I could just check for the attribute instead of testing 
isinstance), but it seemed like a lot of overhead for not much gain (at 
least, for the intended uses of Bunch -- see the "generic object - 
moving toward PEP" and "generic object implementation" threads.)

Steve



More information about the Python-list mailing list