From 2b1461bf542929966ae0b529627a6a2cc2503eae Mon Sep 17 00:00:00 2001 From: aph Date: Sat, 8 Dec 2012 17:32:00 +0000 Subject: [PATCH 1/3] make make_overload_check return True instead of empty string if no checks to be made --- pythongen.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pythongen.py b/pythongen.py index 584c4b373cc9..af5013a696b1 100644 --- a/pythongen.py +++ b/pythongen.py @@ -262,7 +262,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) From e9eeb9f6f4c1791cb9ad1a966e55f74c2df49fac Mon Sep 17 00:00:00 2001 From: aph Date: Sat, 8 Dec 2012 17:40:28 +0000 Subject: [PATCH 2/3] add case testOverloadWithAnyType to pythongen.test --- test/data/pythongen.test | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/data/pythongen.test b/test/data/pythongen.test index 6baed448c066..3dd3023d4246 100644 --- a/test/data/pythongen.test +++ b/test/data/pythongen.test @@ -456,3 +456,19 @@ 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") From 03ed7a0af8c501b488346cd891954d69be0a4770 Mon Sep 17 00:00:00 2001 From: aph Date: Sat, 8 Dec 2012 17:49:29 +0000 Subject: [PATCH 3/3] fix another overloading corner case --- pythongen.py | 4 +++- test/data/pythongen.test | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/pythongen.py b/pythongen.py index af5013a696b1..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: diff --git a/test/data/pythongen.test b/test/data/pythongen.test index 3dd3023d4246..0315cbf6a79b 100644 --- a/test/data/pythongen.test +++ b/test/data/pythongen.test @@ -472,3 +472,17 @@ def f(x): 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")