Multiple Dispatch not required value
Question:
I had a method like this on python:
def method(a, b, c: int=0):
return a+b+c
When I called method(5,2) it returns me 7.
However when I want to use multiple dispatching:
from multipledispatch import dispatch
@dispatch(int, int, int)
def method(a, b, c=0):
return a+b+c
method(5,2) understandably gives an error. Is there any way to make one of the values in dispatch not required like a ref statement on c#?
Answers:
This will work (you need to specify the names of args with default values when using @dispatch).
@dispatch(int, int, c=int)
def method(a, b, c=0):
return a+b+c
method(2,7)
# Out[58]: 9
I had a method like this on python:
def method(a, b, c: int=0):
return a+b+c
When I called method(5,2) it returns me 7.
However when I want to use multiple dispatching:
from multipledispatch import dispatch
@dispatch(int, int, int)
def method(a, b, c=0):
return a+b+c
method(5,2) understandably gives an error. Is there any way to make one of the values in dispatch not required like a ref statement on c#?
This will work (you need to specify the names of args with default values when using @dispatch).
@dispatch(int, int, c=int)
def method(a, b, c=0):
return a+b+c
method(2,7)
# Out[58]: 9