Should proxy objects lie about their class name?

Diez B. Roggisch deets at nospam.web.de
Mon Nov 26 14:00:58 EST 2007


John J. Lee schrieb:
> jjl at pobox.com (John J. Lee) writes:
> 
>> Not much to add to the subject line.  I mean something like this:
>>
>> ProxyClass.__name__ = ProxiedClass.__name__
>>
>>
>> I've been told that this is common practice.  Is it?  Would this
>> surprise you if you ran into it in a debugging session?
> 
> Does nobody have an opinion on this?  Pull your socks up, c.l.py!
> 
> <insert reference to argument sketch here>

I've written quite a few proxies, but none of them did that. IMHO this 
is similar to using isinstance overeagerly: it works against the 
duck-typing principle to guard code by requiring certain base-classes, 
instead of just relying on protocol. The same applies here.

There might be of course cases where you have code lying around that 
does do some distinctions based on the class-name (I'm certainly I've 
seen such stuff once or tiwce, but always regarded it a WTF). Then doing 
as you do above might help in getting things work.

Diez



More information about the Python-list mailing list