Skip to content

stubgen: don't append star arg when args list already has varargs appended #4518

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion mypy/stubgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions test-data/unit/stubgen.test
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down