Report an error about an incompatible argument type. The argument type is arg_type, argument number is n and the callee type is 'callee'. If the callee represents a method that corresponds to an operator, use the corresponding operator name in the messages.
(
self,
n: int,
m: int,
callee: CallableType,
arg_type: Type,
arg_kind: ArgKind,
object_type: Type | None,
context: Context,
outer_context: Context,
)
| 591 | return AnyType(TypeOfAny.from_error) |
| 592 | |
| 593 | def incompatible_argument( |
| 594 | self, |
| 595 | n: int, |
| 596 | m: int, |
| 597 | callee: CallableType, |
| 598 | arg_type: Type, |
| 599 | arg_kind: ArgKind, |
| 600 | object_type: Type | None, |
| 601 | context: Context, |
| 602 | outer_context: Context, |
| 603 | ) -> ErrorInfo: |
| 604 | """Report an error about an incompatible argument type. |
| 605 | |
| 606 | The argument type is arg_type, argument number is n and the |
| 607 | callee type is 'callee'. If the callee represents a method |
| 608 | that corresponds to an operator, use the corresponding |
| 609 | operator name in the messages. |
| 610 | |
| 611 | Return the error code that used for the argument (multiple error |
| 612 | codes are possible). |
| 613 | """ |
| 614 | arg_type = get_proper_type(arg_type) |
| 615 | |
| 616 | target = "" |
| 617 | callee_name = callable_name(callee) |
| 618 | if callee_name is not None: |
| 619 | name = callee_name |
| 620 | if object_type is not None: |
| 621 | base = format_type(object_type, self.options) |
| 622 | else: |
| 623 | base = extract_type(name) |
| 624 | |
| 625 | if name.startswith('"__getitem__" of'): |
| 626 | return self.invalid_index_type( |
| 627 | arg_type, callee.arg_types[n - 1], base, context, code=codes.INDEX |
| 628 | ) |
| 629 | elif name.startswith('"__setitem__" of'): |
| 630 | if n == 1: |
| 631 | return self.invalid_index_type( |
| 632 | arg_type, callee.arg_types[n - 1], base, context, code=codes.INDEX |
| 633 | ) |
| 634 | else: |
| 635 | arg_type_str, callee_type_str = format_type_distinctly( |
| 636 | arg_type, callee.arg_types[n - 1], options=self.options |
| 637 | ) |
| 638 | info = ( |
| 639 | f" (expression has type {arg_type_str}, target has type {callee_type_str})" |
| 640 | ) |
| 641 | error_msg = ( |
| 642 | message_registry.INCOMPATIBLE_TYPES_IN_ASSIGNMENT.with_additional_msg(info) |
| 643 | ) |
| 644 | return self.fail(error_msg.value, context, code=error_msg.code) |
| 645 | elif name.startswith('"__'): |
| 646 | for method, op in op_methods_to_symbols.items(): |
| 647 | for variant in method, "__r" + method[2:]: |
| 648 | # FIX: do not rely on textual formatting |
| 649 | if name.startswith(f'"{variant}" of'): |
| 650 | if op == "in" or variant != method: |
no test coverage detected