Skip to content

Commit

Permalink
stubgen: fix non default keyword-only argument positioning (#12303)
Browse files Browse the repository at this point in the history
Fixes #11082
  • Loading branch information
shoracek authored Mar 8, 2022
1 parent 226661f commit 8650f5c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 4 additions & 2 deletions mypy/stubgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 == '':
Expand Down
5 changes: 5 additions & 0 deletions test-data/unit/stubgen.test
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ...): ...

0 comments on commit 8650f5c

Please sign in to comment.