I have a requirement in my application where I need to call a method with same name, but with different number arguments and implementations. Also, I do not want to add any conditional statements which check the arguments received and execute the required implementation. This would have been straight-forward with languages like Java, C++ where function overloading is possible.
I looked into python packages like https://github.com/mrocklin/multipledispatch/blob/master/multipledispatch/ which provide this support, but it seems to be an overhead for the application to depend on such external libraries for the use-case.
Following is what I'm trying to achieve:
def foo(x):
do_something
def foo(x,y):
do_something_else
Without doing the following:
def foo(x, y=None):
if not y:
do_something
else:
do_something_else