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#?

Asked By: String

||

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
Answered By: Swifty
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.