[PEAK] generic function signature changes
Simon Belak
simon.belak at hruska.si
Thu Jun 15 14:41:38 EDT 2006
I don't think so:
from dispatch import generic
@generic()
def foo(bar):
pass
@foo.when("bar > 2")
def foo_gt_2(bar):
return "bar > 2"
@foo.when("bar == 2")
def foo_gt_2(bar, baz=24):
return baz
print foo(4)
print foo(2)
Arguments just need to be optional or keyword.
Cheers,
Simon
Kevin Dangoor wrote:
> Am I correct that it is harder to change a generic function's
> signature than it is to change an ordinary function's signature? Let's
> say you have this function:
>
> def foo(bar)
>
> As an ordinary Python function, you can do this:
>
> def foo(bar, baz=None)
>
> without breaking any subclasses (if this were a method) or anyone else
> using the function. But, if you add an additional, even optional,
> parameter to a generic function, all of the implementers of that
> function need to change as well...
>
> Is that right?
>
> Kevin
>
More information about the PEAK
mailing list