coady / multimethod

Multiple argument dispatching.
https://coady.github.io/multimethod
Other
284 stars 23 forks source link

Variable positional arguments #115

Closed sylvorg closed 8 months ago

sylvorg commented 8 months ago

Hello! Sorry, it's me again! 😅

Is there any way to implement a variable number of positional arguments, like in the following example:

from multimethod import multimethod

@multimethod
def call():
    print("Hello, world!")

@multimethod
def call(name):
    print(f"Hello, {name}!")

call() # Hello, world!
call("Foo") # Hello, Foo!

Thank you kindly for the help, and sorry again for the multiple issues!

coady commented 8 months ago

multimethod supports variable arguments, but there are no types in the example. The pythonic way to do this kind of "overloading" is to use defaults.

def call(name="world"):
    print(f"Hello, {name}!")
sylvorg commented 8 months ago

Actually, speaking of which, how do you use multidispatch with defaults / keyword arguments? And are they the same thing?