Skip to content

Commit 8650f5c

Browse files
authored
stubgen: fix non default keyword-only argument positioning (#12303)
Fixes #11082
1 parent 226661f commit 8650f5c

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

mypy/stubgen.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -649,9 +649,11 @@ def visit_func_def(self, o: FuncDef, is_abstract: bool = False,
649649
# type "UnboundType" and will not match.
650650
if not isinstance(get_proper_type(annotated_type), AnyType):
651651
annotation = ": {}".format(self.print_annotation(annotated_type))
652+
653+
if kind.is_named() and not any(arg.startswith('*') for arg in args):
654+
args.append('*')
655+
652656
if arg_.initializer:
653-
if kind.is_named() and not any(arg.startswith('*') for arg in args):
654-
args.append('*')
655657
if not annotation:
656658
typename = self.get_str_type_of_node(arg_.initializer, True, False)
657659
if typename == '':

test-data/unit/stubgen.test

+5
Original file line numberDiff line numberDiff line change
@@ -2580,3 +2580,8 @@ class A:
25802580
def f(x: int, y: int) -> int: ...
25812581
@t.overload
25822582
def f(x: t.Tuple[int, int]) -> int: ...
2583+
2584+
[case testNonDefaultKeywordOnlyArgAfterAsterisk]
2585+
def func(*, non_default_kwarg: bool, default_kwarg: bool = True): ...
2586+
[out]
2587+
def func(*, non_default_kwarg: bool, default_kwarg: bool = ...): ...

0 commit comments

Comments
 (0)