Should proxy objects lie about their class name?

Fuzzyman fuzzyman at gmail.com
Tue Nov 27 17:25:38 CET 2007


On Nov 26, 11:56 pm, Carl Banks <pavlovevide... at gmail.com> wrote:
> On Nov 20, 3:50 pm, j... at pobox.com (John J. Lee) wrote:
>
> > 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?
>
> > One very real advantage that I can see is avoiding breaking existing
> > doctests.
>
> > Thanks in advance for your views
>
> Python 3.0 has a proposal, accepted I believe, to allow classes to
> control the behavior of issubclass and ininstance, so there appears to
> be tacit support from the language for mimicking the proxied classes
> in such ways.
>
> I guess for me it would be a judgment call on based how tight I wanted
> the proxy class to be--is it being the class, or is it just standing
> in?


In Python 2 you can already lie to 'isinstance' and 'issubclass' by
catching calls to the '__class__' and '__bases__' attribute. I'm not
sure yet whether this is a good thing however. :-)

I have a proxy class I want to extend and am facing similar questions.

Michael
http://www.manning.com/foord

>
> Carl Banks




More information about the Python-list mailing list