Check for extra actual arguments. Return tuple (was everything ok, was there an extra keyword argument error [used to avoid duplicate errors]).
(
self,
callee: CallableType,
actual_types: list[Type],
actual_kinds: list[ArgKind],
actual_names: Sequence[str | None] | None,
all_actuals: dict[int, int],
context: Context,
)
| 2501 | return ok |
| 2502 | |
| 2503 | def check_for_extra_actual_arguments( |
| 2504 | self, |
| 2505 | callee: CallableType, |
| 2506 | actual_types: list[Type], |
| 2507 | actual_kinds: list[ArgKind], |
| 2508 | actual_names: Sequence[str | None] | None, |
| 2509 | all_actuals: dict[int, int], |
| 2510 | context: Context, |
| 2511 | ) -> tuple[bool, bool]: |
| 2512 | """Check for extra actual arguments. |
| 2513 | |
| 2514 | Return tuple (was everything ok, |
| 2515 | was there an extra keyword argument error [used to avoid duplicate errors]). |
| 2516 | """ |
| 2517 | |
| 2518 | is_unexpected_arg_error = False # Keep track of errors to avoid duplicate errors |
| 2519 | ok = True # False if we've found any error |
| 2520 | |
| 2521 | for i, kind in enumerate(actual_kinds): |
| 2522 | if ( |
| 2523 | i not in all_actuals |
| 2524 | and |
| 2525 | # We accept the other iterables than tuple (including Any) |
| 2526 | # as star arguments because they could be empty, resulting no arguments. |
| 2527 | (kind != nodes.ARG_STAR or is_non_empty_tuple(actual_types[i])) |
| 2528 | and |
| 2529 | # Accept all types for double-starred arguments, because they could be empty |
| 2530 | # dictionaries and we can't tell it from their types |
| 2531 | kind != nodes.ARG_STAR2 |
| 2532 | ): |
| 2533 | # Extra actual: not matched by a formal argument. |
| 2534 | ok = False |
| 2535 | if kind != nodes.ARG_NAMED: |
| 2536 | self.msg.too_many_arguments(callee, context) |
| 2537 | else: |
| 2538 | assert actual_names, "Internal error: named kinds without names given" |
| 2539 | act_name = actual_names[i] |
| 2540 | assert act_name is not None |
| 2541 | act_type = actual_types[i] |
| 2542 | self.msg.unexpected_keyword_argument(callee, act_name, act_type, context) |
| 2543 | is_unexpected_arg_error = True |
| 2544 | elif ( |
| 2545 | kind == nodes.ARG_STAR and nodes.ARG_STAR not in callee.arg_kinds |
| 2546 | ) or kind == nodes.ARG_STAR2: |
| 2547 | actual_type = get_proper_type(actual_types[i]) |
| 2548 | if isinstance(actual_type, (TupleType, TypedDictType)): |
| 2549 | if all_actuals.get(i, 0) < len(actual_type.items): |
| 2550 | # Too many tuple/dict items as some did not match. |
| 2551 | if kind != nodes.ARG_STAR2 or not isinstance(actual_type, TypedDictType): |
| 2552 | self.msg.too_many_arguments(callee, context) |
| 2553 | else: |
| 2554 | self.msg.too_many_arguments_from_typed_dict( |
| 2555 | callee, actual_type, context |
| 2556 | ) |
| 2557 | is_unexpected_arg_error = True |
| 2558 | ok = False |
| 2559 | # *args/**kwargs can be applied even if the function takes a fixed |
| 2560 | # number of positional arguments. This may succeed at runtime. |
no test coverage detected