diff --git a/mypy/stubgen.py b/mypy/stubgen.py index c1dac63c231d..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 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):