On Wednesday 10 April 2002 04:00 pm, Edmund Lian wrote:
> I'm not advocating against inheritance. What I am advocating is that
> the type check needs to be able to be turned off, or made a bit more
> intelligent.
It's unfortunate that Python places so much emphasis on global
functions:
isinstance(obj, Class)
Over methods:
obj.isinstance(Class)
Otherwise you could override this easily for your delegation case. Does
isinstance() happen to call one those quadruple underscore methods by
any chance?
On Wednesday 10 April 2002 04:25 pm, Edmund Lian wrote:
> class PseudoServlet:
> � � def __init__(self):
> � � � � # Create and store instance of a real servlet
> � � � � self.__dict__['realservlet'] = Servlet()
>
> � � def myMethod1(self):
> � � � � do stuff
>
> � � def __getattr__(self, name):
> � � � � return getattr(self.realservlet, name)
>
> � � def __setattr__(self, name, value):
> � � � � return setattr(self.realservlet, name, value)
>
> Originally, I did this to get around a multiple inheritance problem
> that I was having with Cheetah, where I could not override the base
> template's .awake() method due to the way Python < 2.2 was resolving
> multiple inheritance. Cheetah has since been modified to only support
> single inheritance.
>
> However, I'm still using delegation to get around weak encapsulation
> and other issues that I ran into when writing servlets. The issues
> I'm referring to are discussed in the following links:
How has Cheetah been modified such that you can't use multiple
inheritance? Isn't that a Python thing, or is this an issue with an
#extend directive or something similar?
It doesn't feel like the above example really deals with weak
encapsulation and such since all unknown attributes just get passed on
to the delegate anyway. That's almost like implementing your own
inheritance. Maybe the example is just over-simplified.
Can you inherit from Servlet, but then use the new __getattribute__ in
a such a way to get the behavior you want?
If not, then the final solution that comes to my mind is to tweak
WebKit like so:
if not isinstance(servlet, Servlet) and \
not getattr(servlet, 'isServlet', None):
raise ValueError, 'The instance is not a servlet.'
e.g., for those developers that really know what they're doing, an
"isServlet = 1" attr will bypass the test. It would be expected that an
instance never revert to "isServlet=0" after being served up by WebKit.
-Chuck
_______________________________________________
Webware-discuss mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/webware-discuss