diff --git a/mypy/stubgen.py b/mypy/stubgen.py index b0a2c4e64587..dafb446a835a 100755 --- a/mypy/stubgen.py +++ b/mypy/stubgen.py @@ -649,9 +649,11 @@ def visit_func_def(self, o: FuncDef, is_abstract: bool = False, # type "UnboundType" and will not match. if not isinstance(get_proper_type(annotated_type), AnyType): annotation = ": {}".format(self.print_annotation(annotated_type)) + + if kind.is_named() and not any(arg.startswith('*') for arg in args): + args.append('*') + if arg_.initializer: - if kind.is_named() and not any(arg.startswith('*') for arg in args): - args.append('*') if not annotation: typename = self.get_str_type_of_node(arg_.initializer, True, False) if typename == '': diff --git a/test-data/unit/stubgen.test b/test-data/unit/stubgen.test index e20073027db2..6592791f9aa3 100644 --- a/test-data/unit/stubgen.test +++ b/test-data/unit/stubgen.test @@ -2580,3 +2580,8 @@ class A: def f(x: int, y: int) -> int: ... @t.overload def f(x: t.Tuple[int, int]) -> int: ... + +[case testNonDefaultKeywordOnlyArgAfterAsterisk] +def func(*, non_default_kwarg: bool, default_kwarg: bool = True): ... +[out] +def func(*, non_default_kwarg: bool, default_kwarg: bool = ...): ...