Skip to content

Support for both variable number of args and keyword args? #87

Closed Answered by coady
andrewtruong asked this question in Q&A
Discussion options

You must be logged in to vote

Yes, it has the limitation that it uses the first definition as the signature. The only general way to be that flexible would be check each function, which is what overload does. So if the performance difference isn't relevant for your case, that will work.

from multimethod import overload

@overload
def f(a,b): ...

@f.register
def f(a:int, b:int): return a+b

@f.register
def f(a:int, b:int, c:int): return a+b+c

Replies: 5 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by coady
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants