書いた本人に必要性が分からないシリーズ
import sys class OverloadMethod(object): def __init__(self): self.functions = [] def __call__(self, *args, **kwargs): for function in self.functions: if len(args) == function.func_code.co_argcount: return function(*args) raise ValueError def overload(function): obj = sys._getframe(1).f_globals.get(function.__name__) if obj is None: obj = OverloadMethod() obj.functions.append(function) return obj if __name__ == '__main__': class Foo(object): @overload def foo(a): print a @overload def foo(a, b): print a + b foo(1) foo(1, 2) Foo().foo(1) Foo().foo(1, 2)