From 344e07e1443a08235c37f7e9c022c7c1274befc3 Mon Sep 17 00:00:00 2001 From: hoefling Date: Sun, 28 Jan 2018 22:01:08 +0100 Subject: [PATCH 1/2] stubgen: don't append star arg when args list already has varargs appended (#3985) --- mypy/stubgen.py | 2 +- test-data/unit/stubgen.test | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/mypy/stubgen.py b/mypy/stubgen.py index c1dac63c231d..643839ea2381 100644 --- a/mypy/stubgen.py +++ b/mypy/stubgen.py @@ -457,7 +457,7 @@ def visit_func_def(self, o: FuncDef) -> None: annotation = "" if arg_.initializer: initializer = '...' - if kind in (ARG_NAMED, ARG_NAMED_OPT) and '*' not in args: + if kind in (ARG_NAMED, ARG_NAMED_OPT) and not any(arg.startswith('*') for arg in args): args.append('*') if not annotation: typename = self.get_str_type_of_node(arg_.initializer, True) diff --git a/test-data/unit/stubgen.test b/test-data/unit/stubgen.test index aa8b6136d660..a1da36af2f02 100644 --- a/test-data/unit/stubgen.test +++ b/test-data/unit/stubgen.test @@ -82,6 +82,19 @@ def f(x, **y): ... [out] def f(x, **y) -> None: ... +[case testVarArgsWithKwVarArgs] +def f(a, *b, **c): ... +def g(a, *b, c=1): ... +def h(a, *b, c=1, **d): ... +def i(a, *, b=1): ... +def j(a, *, b=1, **c): ... +[out] +def f(a, *b, **c) -> None: ... +def g(a, *b, c: int = ...) -> None: ... +def h(a, *b, c: int = ..., **d) -> None: ... +def i(a, *, b: int = ...) -> None: ... +def j(a, *, b: int = ..., **c) -> None: ... + [case testClass] class A: def f(self, x): From 8b9f1c137d181e4cdac4eaf122dda5e312e63cab Mon Sep 17 00:00:00 2001 From: hoefling Date: Sun, 28 Jan 2018 22:25:11 +0100 Subject: [PATCH 2/2] fixed flake warning --- mypy/stubgen.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mypy/stubgen.py b/mypy/stubgen.py index 643839ea2381..07e85adb34da 100644 --- a/mypy/stubgen.py +++ b/mypy/stubgen.py @@ -457,7 +457,8 @@ def visit_func_def(self, o: FuncDef) -> None: annotation = "" if arg_.initializer: initializer = '...' - if kind in (ARG_NAMED, ARG_NAMED_OPT) and not any(arg.startswith('*') for arg in args): + if kind in (ARG_NAMED, ARG_NAMED_OPT) and not any(arg.startswith('*') + for arg in args): args.append('*') if not annotation: typename = self.get_str_type_of_node(arg_.initializer, True)