File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2360,8 +2360,9 @@ def _detect_missing_positional_arg(
23602360 """Try to identify a single missing positional argument using type alignment.
23612361
23622362 If the caller and callee are just positional arguments and exactly one arg is missing,
2363- we scan left to right to find which argument skipped. If there is an error, report it
2364- and return True, or return False to fall back to normal checking.
2363+ we scan left to right to find which argument skipped. If only the last argument is missing,
2364+ we return False since it's already handled in a desired manner. If there is an error,
2365+ report it and return True, or return False to fall back to normal checking.
23652366 """
23662367 if not all (k == ARG_POS for k in callee .arg_kinds ):
23672368 return False
@@ -2386,6 +2387,9 @@ def _detect_missing_positional_arg(
23862387 if skip_idx is None or j != len (arg_types ):
23872388 return False
23882389
2390+ if skip_idx == len (callee .arg_types ) - 1 :
2391+ return False
2392+
23892393 param_name = callee .arg_names [skip_idx ]
23902394 callee_name = callable_name (callee )
23912395 if param_name is None or callee_name is None :
Original file line number Diff line number Diff line change @@ -3746,6 +3746,22 @@ main:3: error: Missing positional argument "z" in call to "f"
37463746main:3: error: Argument 1 to "f" has incompatible type "str"; expected "int"
37473747main:3: error: Argument 2 to "f" has incompatible type "int"; expected "str"
37483748
3749+ [case testMissingPositionalArgNoShiftPatternLast]
3750+ def f(x: int, y: str, z: bytes) -> None: ...
3751+
3752+ f(123, "wrong")
3753+ [builtins fixtures/primitives.pyi]
3754+ [out]
3755+ main:3: error: Missing positional argument "z" in call to "f"
3756+
3757+ [case testMissingPositionalArgNoShiftPatternNone]
3758+ def f(x: int) -> None: ...
3759+
3760+ f()
3761+ [builtins fixtures/primitives.pyi]
3762+ [out]
3763+ main:3: error: Missing positional argument "x" in call to "f"
3764+
37493765[case testMissingPositionalArgMultipleMissing]
37503766def f(a: int, b: str, c: float, d: list[int]) -> None: ...
37513767
You can’t perform that action at this time.
0 commit comments