diff --git a/pythongen.py b/pythongen.py index 584c4b373cc9..241fc573c2d6 100644 --- a/pythongen.py +++ b/pythongen.py @@ -189,7 +189,9 @@ def visit_overloaded_func_def(self, o): rest_args = None if is_more: rest_args = self.make_unique('args', fixed_args) - self.string(', *{}'.format(rest_args)) + if len(fixed_args) > 0: + self.string(', ') + self.string('*{}'.format(rest_args)) self.string('):\n' + indent) n = 1 for f in o.items: @@ -262,7 +264,10 @@ def make_overload_check(self, f, fixed_args, rest_args): a.append(self.make_argument_check( self.argument_ref(i, fixed_args, rest_args), t)) i += 1 - return ' and '.join(a) + if len(a) > 0: + return ' and '.join(a) + else: + return 'True' def make_argument_count_check(self, f, num_fixed, rest_args): return 'len({}) == {}'.format(rest_args, f.min_args - num_fixed) diff --git a/test/data/pythongen.test b/test/data/pythongen.test index 6baed448c066..0315cbf6a79b 100644 --- a/test/data/pythongen.test +++ b/test/data/pythongen.test @@ -456,3 +456,33 @@ class A: [out] class A: def f(self): pass + +[case testOverloadWithAnyType] +class A: pass +def f(A x): pass +def f(x): pass +[out] +class A: pass +def f(x): + def f1(x): pass + def f2(x): pass + if isinstance(x, A): + return f1(x) + elif True: + return f2(x) + else: + raise TypeError("Invalid argument types") + +[case testOverloadWithZeroArgs] +def f(x): pass +def f(): pass +[out] +def f(*args): + def f1(x): pass + def f2(): pass + if len(args) == 1: + return f1(args[0]) + elif len(args) == 0: + return f2() + else: + raise TypeError("Invalid argument types")