Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions pythongen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down
30 changes: 30 additions & 0 deletions test/data/pythongen.test
Original file line number Diff line number Diff line change
Expand Up @@ -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")