I write my answer in Python 3.2.1.
def overload(*functions):
return lambda *args, **kwargs: functions[len(args)](*args, **kwargs)
How it works:
overload
takes any amount of callables and stores them in tuple functions
, then returns lambda.functions[number_of_unnamed_args_passed]
called with arguments passed to the lambda.Usage:
class A:
stackoverflow=overload( \
None, \
#there is always a self argument, so this should never get called
lambda self: print('First method'), \
lambda self, i: print('Second method', i) \
)