[Python-3000] PEP 3124 - Overloading, Generic Functions, Interfaces, etc.
talin at acm.org
Wed May 2 04:21:28 CEST 2007
Phillip J. Eby wrote:
> At 09:13 AM 5/1/2007 -0700, Talin wrote:
>> Phillip J. Eby wrote:
>>> Proceeding to the "Next" Method
>>> If the first parameter of an overloaded function is named
>>> ``__proceed__``, it will be passed a callable representing the next
>>> most-specific method. For example, this code::
>>> def foo(bar:object, baz:object):
>>> print "got objects!"
>>> def foo(__proceed__, bar:int, baz:int):
>>> print "got integers!"
>>> return __proceed__(bar, baz)
>> I don't care for the idea of testing against a specially named
>> argument. Why couldn't you just have a different decorator, such as
>> "overload_chained" which triggers this behavior?
> The PEP lists *five* built-in decorators, all of which support this
> @overload, @when, @before, @after, @around
> And in addition, it demonstrates how to create *new* method combination
> decorators, that *also* support this behavior (e.g. '@discount').
> All in all, there are an unbounded number of possible decorators that
> would require chained and non-chained variations.
Well, I suppose you could make "chained" a modifier of the decorator, so
for example @operator.chained, @discount.chained, and so on. In other
words, the decorator can be called directly, or the attribute 'chained'
also produces a callable that causes the modified behavior. Moreover,
this would support an arbitrary number of modifiers on the decorator,
such as @overload.chained.strict(True).whatever.
More information about the Python-3000