Skip to content

Commit 9f38602

Browse files
committed
Only non-defaulted args can be required
1 parent 0158dfe commit 9f38602

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

mypy/expandtype.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ def _possible_callable_varargs(
313313
required_posargs = required_prefix
314314
optional_posargs: list[Type] = []
315315
for kind, name, type in zip(repl.arg_kinds, repl.arg_names, repl.arg_types):
316-
if kind.is_positional() and name is None:
316+
if kind == ArgKind.ARG_POS and name is None:
317317
if optional_posargs:
318318
# May happen following Unpack expansion without kinds correction
319319
required_posargs += optional_posargs

test-data/unit/check-parameter-specification.test

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2639,6 +2639,8 @@ def f9(x: int, *args: Unpack[tuple[str, int]]) -> int:
26392639
return 0
26402640
def f10(x: int=0, *args: Unpack[tuple[str, ...]]) -> int:
26412641
return 0
2642+
def f11(x: int = 0, /) -> int:
2643+
return 0
26422644

26432645
reveal_type(Sneaky(f1).args) # N: Revealed type is "tuple[()]"
26442646
reveal_type(SneakyPrefix(f1).args) # E: Missing positional argument "_" in call to "SneakyPrefix" \
@@ -2674,6 +2676,8 @@ reveal_type(SneakyPrefix(f9, 1, '', 0).args) # N: Revealed type is "tuple[built
26742676

26752677
reveal_type(Sneaky(f10, 1, '', '').args) # N: Revealed type is "Union[tuple[()], tuple[builtins.int], tuple[builtins.int, Unpack[builtins.tuple[builtins.str, ...]]]]"
26762678
reveal_type(SneakyPrefix(f10, 1, '', '').args) # N: Revealed type is "Union[tuple[()], tuple[Unpack[builtins.tuple[builtins.str, ...]]]]"
2679+
2680+
reveal_type(Sneaky(f11).args) # N: Revealed type is "Union[tuple[()], tuple[builtins.int]]"
26772681
[builtins fixtures/paramspec.pyi]
26782682

26792683

0 commit comments

Comments
 (0)