Skip to content

Mark varargs as pos-only #19022

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 5 commits into from
May 5, 2025
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
2 changes: 1 addition & 1 deletion mypy/argmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def map_actuals_to_formals(
elif actual_kind.is_named():
assert actual_names is not None, "Internal error: named kinds without names given"
name = actual_names[ai]
if name in formal_names:
if name in formal_names and formal_kinds[formal_names.index(name)] != nodes.ARG_STAR:
formal_to_actual[formal_names.index(name)].append(ai)
elif nodes.ARG_STAR2 in formal_kinds:
formal_to_actual[formal_kinds.index(nodes.ARG_STAR2)].append(ai)
Expand Down
8 changes: 8 additions & 0 deletions test-data/unit/check-varargs.test
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,14 @@ f(*it1, 1, *it2, 2) # E: Argument 3 to "f" has incompatible type "*Tuple[str]";
f(*it1, '') # E: Argument 2 to "f" has incompatible type "str"; expected "int"
[builtins fixtures/for.pyi]

[case testCallVarArgsWithMatchingNamedArgument]
def foo(*args: int) -> None: ... # N: "foo" defined here
foo(args=1) # E: Unexpected keyword argument "args" for "foo"

def bar(*args: int, **kwargs: str) -> None: ...
bar(args=1) # E: Argument "args" to "bar" has incompatible type "int"; expected "str"
[builtins fixtures/for.pyi]


-- Calling varargs function + type inference
-- -----------------------------------------
Expand Down