|
45 | 45 | ClassDef, |
46 | 46 | Context, |
47 | 47 | Expression, |
| 48 | + Decorator, |
48 | 49 | FuncDef, |
49 | 50 | IndexExpr, |
50 | 51 | MypyFile, |
@@ -772,13 +773,27 @@ def incompatible_argument( |
772 | 773 | actual_type_str, expected_type_str |
773 | 774 | ) |
774 | 775 | else: |
775 | | - if self.prefer_simple_messages(): |
| 776 | + try: |
| 777 | + expected_type = callee.arg_types[m - 1] |
| 778 | + except IndexError: # Varargs callees |
| 779 | + expected_type = callee.arg_types[-1] |
| 780 | + |
| 781 | + decorator_context = callee_name is None and isinstance(outer_context, Decorator) |
| 782 | + simple_message = self.prefer_simple_messages() and not decorator_context |
| 783 | + |
| 784 | + if decorator_context: |
| 785 | + arg_type_str, expected_type_str = format_type_distinctly( |
| 786 | + arg_type, expected_type, bare=True, options=self.options |
| 787 | + ) |
| 788 | + func_name = outer_context.func.name |
| 789 | + msg = ( |
| 790 | + f'Decorated function "{func_name}" has incompatible type ' |
| 791 | + f'{quote_type_string(arg_type_str)}; expected ' |
| 792 | + f'{quote_type_string(expected_type_str)}' |
| 793 | + ) |
| 794 | + elif simple_message: |
776 | 795 | msg = "Argument has incompatible type" |
777 | 796 | else: |
778 | | - try: |
779 | | - expected_type = callee.arg_types[m - 1] |
780 | | - except IndexError: # Varargs callees |
781 | | - expected_type = callee.arg_types[-1] |
782 | 797 | arg_type_str, expected_type_str = format_type_distinctly( |
783 | 798 | arg_type, expected_type, bare=True, options=self.options |
784 | 799 | ) |
@@ -822,6 +837,7 @@ def incompatible_argument( |
822 | 837 | quote_type_string(arg_type_str), |
823 | 838 | quote_type_string(expected_type_str), |
824 | 839 | ) |
| 840 | + if not simple_message: |
825 | 841 | expected_type = get_proper_type(expected_type) |
826 | 842 | if isinstance(expected_type, UnionType): |
827 | 843 | expected_types = list(expected_type.items) |
|
0 commit comments