473,386 Members | 1,606 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Should proxy objects lie about their class name?

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
John
Nov 20 '07 #1
7 1192
jj*@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>
John
Nov 26 '07 #2
John J. Lee schrieb:
jj*@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
Nov 26 '07 #3
On Nov 20, 3:50 pm, j...@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?
Carl Banks
Nov 27 '07 #4
On Nov 26, 11:56 pm, Carl Banks <pavlovevide...@gmail.comwrote:
On Nov 20, 3:50 pm, j...@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
Nov 27 '07 #5
Fuzzyman wrote:
On Nov 26, 11:56 pm, Carl Banks <pavlovevide...@gmail.comwrote:
>On Nov 20, 3:50 pm, j...@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.

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.

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. :-)
The Python 3 machinery allows *other* classes to lie about whether or
not your object is an instance or subclass of them, without requiring
them to set your __class__ or __bases__. So, for example, you can
create a class ``Integer`` and make ``issubclass(int, Integer)`` true.
For more information see:

http://www.python.org/dev/peps/pep-3119/

STeVe
Nov 27 '07 #6
Steven Bethard wrote:
........
The Python 3 machinery allows *other* classes to lie about whether or
not your object is an instance or subclass of them, without requiring
them to set your __class__ or __bases__. So, for example, you can
create a class ``Integer`` and make ``issubclass(int, Integer)`` true.
For more information see:

http://www.python.org/dev/peps/pep-3119/

STeVe
That will allow me to magically create instances which claim to be instances of
working_class even though they're actually instances of reactionary_class thus
turning all my modules into instances of class_war :)
--
Robin Becker

Nov 27 '07 #7
"Diez B. Roggisch" <de***@nospam.web.dewrites:
John J. Lee schrieb:
>jj*@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.
Sure. The push here was the doctest issue.

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.
Right.

The actual case I'm talking about here involved an exception class
(dynamically created by subclassing at runtime, eugh) -- and a common
one at that -- so it's a pretty common thing in doctests and any
workaround on the doctest level would be very ugly (of course,
alternatives include working around it by wrapping the code that
raises the exception, or changing the doctest files to use the new
exception name).

What worries me is the potential for confusion. Again, would it
confuse you (not just Diez, everybody)?
John
Nov 27 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Clive Backham | last post by:
I tried posting this on comp.infosystems.www.misc, but that group appears to get very little traffic. So now I'm trying here. If there is a more appropriate group, please let me know. I'm...
2
by: Jonas Cord | last post by:
Hi, I'm trying to learn proxy classes in C++ so I've written the following code, trying to modify an example given in Deitel & Deitel's C++ book. I am trying to "hide" details of the original...
3
by: ytrewq | last post by:
Should dynamic ("expando") properties be restricted to native and user-defined objects? Or should host objects - such as references to the browser or a plug-in or to the document and its elements -...
1
by: ffhansix | last post by:
Hi, I am having problems with generating a c# proxy class from a IBM websphere WSDL file, when running the wsdl.exe to create the c# proxy file command i recieve an error: Warning: one or...
4
by: Dave Langley | last post by:
I'm using VC++ to write an VC++ unmanaged client to communicate to a C#.NET web service. I have the proxy class for the unmanaged client and it uses the default CSoapSocketClientT<> template as...
1
by: TS | last post by:
Hi, i have some common classes that i pass from my client app through the web services to my server side app. I have their assembly referenced in both places. The proxy automatically creates its...
1
by: Scott | last post by:
We have a c# webform application that uses ASP.NET webservices to communicate with our IIS server over the public internet. The customer is complaining that our application is using their default...
5
by: HenrySeque | last post by:
I have a webservice and I add a web reference from my web project. I want the proxy class to implements an Interface, but I didn't find the source code of the proxy class and I don't want to...
3
by: Arpan | last post by:
Web Services make use of proxy classes whose methods & properties are accessed in exactly the same way as how a normal class' methods & properties are accessed. So what for does ASP.NET generate...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.