O_o
No
native function overloading
o_O
I fixed that for you.
Sure, the example is simple. You need to instill quite a lot more power to give enough juice to be really useful, but the example shows the beginning of a possible path, and I would imagine that anyone using a version with decorators would prefer the sugar.
Soma
Code:
class FunctionOverloadable(object):
def __init__(self):
self.mSignature = {}
def __call__(self, *args):
self.mSignature[tuple(c.__class__ for c in args)](*args)
def overload(self, fSignature, fImplementation):
self.mSignature[fSignature] = fImplementation
DoSomething = FunctionOverloadable()
def DoSomethingImplementation(f):
print("int")
DoSomething.overload((int,), DoSomethingImplementation)
def DoSomethingImplementation(f):
print("float")
DoSomething.overload((float,), DoSomethingImplementation)
DoSomething(1)
DoSomething(1.0)