Push the delegate's 'self' through to Pass-through calls on the context
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
lazr.delegates |
Invalid
|
Undecided
|
Unassigned |
Bug Description
I wonder if it's been discussed whether we could call pass-through methods using the delegate's self, rather than the context? ie:
= Steps to reproduce =
{{{
>>> from zope.interface import Interface
>>> class IMyClass(
... def superExpensiveQ
... """Does lots of stuff"""
... def otherQueryThatU
... """Calls superExpensiveQ
...
>>> class MyClass(object):
... implements(
... def superExpensiveQ
... print "Lots of heavy queries"
... def otherQueryThatU
... self.superExpen
...
>>> myclassobj = MyClass()
>>> myclassobj.
Lots of heavy queries
>>> class MyDelegateClass
... delegates(IMyClass)
... def __init__(self, context):
... self.context = context
... def superExpensiveQ
... print "Nice quick cached version"
...
>>> mydelobj = MyDelegateClass
>>> mydelobj.
Nice quick cached version
}}}
= Expected Result =
When calling mydelobj.
= Actual Result =
{{{
>>> mydelobj.
Lots of heavy queries
}}}
To do this at the moment the code looks very hacky, ie. in the definition of MyDelegateClass, adding:
{{{
def otherQueryThatU
return MyClass.
}}}
tags: | added: tech-debt |
This isn't something we should do as it really breaks the type system.
A delegate isn't a subclass of the delegated class, so passing itself as self is likely to break code (if any method depends on private/protected attributes).