Kurt B. Kaiser added the comment:

Despite your explanation, I don't understand what is being
accomplished here.  Delegates are not intended to be callable.
They have methods, e.g. insert, which are callable, and the
insert call is propagated down the chain by calls like
(from ColorDelegator):

    def insert(self, index, chars, tags=None):
        index = self.index(index)
        self.delegate.insert(index, chars, tags)
        self.notify_range(index, index + "+%dc" % len(chars))

IMHO it's an incorrect usage of the Delegator mixin to
affect the callable nature of the class to which it's being added.

Also, this __call__ method, if actually used, propagates to the
end of the Delegator chain and calls the function at the end,
(assuming it is a function).  Or it will skip non-callable
Delegators and stop at the first callable one.

I doubt this is what was intended, and people trying to understand the code 
will be further confused, it seems to me.

Try adding delegator.txt (below) to your Delegator.py and running the
module!

I think this patch increases the complexity and obscurity of the
Delegator/Percolator/WidgetRedirector code, rather than improving
it.  Apparently you want to sometimes call a chain of methods (as
in current usage) and sometimes call a chain of functions. The
semantic overload, which was bad enough already, is too great.

If Squeezer and ShellLogger require this change, then I'd
suggest changing them to match current Percolator usage, instead.
Currently I don't see a Delegator being used in Squeezer.  Could
you be more specific about why the change is needed for those
two extensions?

Added file: http://bugs.python.org/file8604/delegator.txt

__________________________________
Tracker <[EMAIL PROTECTED]>
<http://bugs.python.org/issue1252>
__________________________________
class Hooker(Delegator):

    def __init__(self):
        Delegator.__init__(self)


class Interceptor(Delegator):

    def __init__(self):
        Delegator.__init__(self)

def fcn():
    print "Fcn at base"

if __name__ == "__main__":
    bottom = Hooker()
    bottom.setdelegate(fcn)
    middle = Hooker()
    middle.setdelegate(bottom)
    top = Interceptor()
    top.setdelegate(middle)
    print "top.delegate: ", top.delegate
    print "calling top(): ",
    top()
_______________________________________________
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to