Skip to content

Commit 73e58da

Browse files
hoeflinggvanrossum
authored andcommitted
stubgen: don't append star arg when args list already has varargs appended (#4518)
* stubgen: don't append star arg when args list already has varargs appended (#3985) * fixed flake warning
1 parent 1ec50a9 commit 73e58da

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

mypy/stubgen.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,8 @@ def visit_func_def(self, o: FuncDef) -> None:
457457
annotation = ""
458458
if arg_.initializer:
459459
initializer = '...'
460-
if kind in (ARG_NAMED, ARG_NAMED_OPT) and '*' not in args:
460+
if kind in (ARG_NAMED, ARG_NAMED_OPT) and not any(arg.startswith('*')
461+
for arg in args):
461462
args.append('*')
462463
if not annotation:
463464
typename = self.get_str_type_of_node(arg_.initializer, True)

test-data/unit/stubgen.test

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,19 @@ def f(x, **y): ...
8282
[out]
8383
def f(x, **y) -> None: ...
8484

85+
[case testVarArgsWithKwVarArgs]
86+
def f(a, *b, **c): ...
87+
def g(a, *b, c=1): ...
88+
def h(a, *b, c=1, **d): ...
89+
def i(a, *, b=1): ...
90+
def j(a, *, b=1, **c): ...
91+
[out]
92+
def f(a, *b, **c) -> None: ...
93+
def g(a, *b, c: int = ...) -> None: ...
94+
def h(a, *b, c: int = ..., **d) -> None: ...
95+
def i(a, *, b: int = ...) -> None: ...
96+
def j(a, *, b: int = ..., **c) -> None: ...
97+
8598
[case testClass]
8699
class A:
87100
def f(self, x):

0 commit comments

Comments
 (0)