@@ -19,6 +19,9 @@ class ErrorMessage(NamedTuple):
19
19
def format (self , * args : object , ** kwargs : object ) -> "ErrorMessage" :
20
20
return ErrorMessage (self .value .format (* args , ** kwargs ), code = self .code )
21
21
22
+ # Strings
23
+ INCOMPATIBLE_TYPES : Final = "Incompatible types"
24
+ INCOMPATIBLE_TYPES_IN_ASSIGNMENT : Final = "Incompatible types in assignment"
22
25
23
26
# Invalid types
24
27
INVALID_TYPE_RAW_ENUM_VALUE : Final = ErrorMessage (
@@ -51,17 +54,15 @@ def format(self, *args: object, **kwargs: object) -> "ErrorMessage":
51
54
" its third type parameter in Python 2"
52
55
)
53
56
YIELD_VALUE_EXPECTED : Final = ErrorMessage ("Yield value expected" )
54
- INCOMPATIBLE_TYPES : Final = "Incompatible types"
55
- INCOMPATIBLE_TYPES_IN_ASSIGNMENT : Final = "Incompatible types in assignment"
56
57
INCOMPATIBLE_TYPES_IN_AWAIT : Final = ErrorMessage ('Incompatible types in "await"' )
57
58
INCOMPATIBLE_REDEFINITION : Final = ErrorMessage ("Incompatible redefinition" )
58
- INCOMPATIBLE_TYPES_IN_ASYNC_WITH_AENTER : Final = (
59
+ INCOMPATIBLE_TYPES_IN_ASYNC_WITH_AENTER : Final = ErrorMessage (
59
60
'Incompatible types in "async with" for "__aenter__"'
60
61
)
61
- INCOMPATIBLE_TYPES_IN_ASYNC_WITH_AEXIT : Final = (
62
+ INCOMPATIBLE_TYPES_IN_ASYNC_WITH_AEXIT : Final = ErrorMessage (
62
63
'Incompatible types in "async with" for "__aexit__"'
63
64
)
64
- INCOMPATIBLE_TYPES_IN_ASYNC_FOR : Final = 'Incompatible types in "async for"'
65
+ INCOMPATIBLE_TYPES_IN_ASYNC_FOR : Final = ErrorMessage ( 'Incompatible types in "async for"' )
65
66
66
67
INCOMPATIBLE_TYPES_IN_YIELD : Final = ErrorMessage ('Incompatible types in "yield"' )
67
68
INCOMPATIBLE_TYPES_IN_YIELD_FROM : Final = ErrorMessage ('Incompatible types in "yield from"' )
@@ -72,7 +73,7 @@ def format(self, *args: object, **kwargs: object) -> "ErrorMessage":
72
73
TUPLE_INDEX_OUT_OF_RANGE : Final = ErrorMessage ("Tuple index out of range" )
73
74
INVALID_SLICE_INDEX : Final = ErrorMessage ("Slice index must be an integer or None" )
74
75
CANNOT_INFER_LAMBDA_TYPE : Final = ErrorMessage ("Cannot infer type of lambda" )
75
- CANNOT_ACCESS_INIT : Final = 'Cannot access "__init__" directly'
76
+ CANNOT_ACCESS_INIT : Final = ErrorMessage ( 'Cannot access "__init__" directly' )
76
77
NON_INSTANCE_NEW_TYPE : Final = ErrorMessage ('"__new__" must return a class instance (got {})' )
77
78
INVALID_NEW_TYPE : Final = ErrorMessage ('Incompatible return type for "__new__"' )
78
79
BAD_CONSTRUCTOR_TYPE : Final = ErrorMessage ("Unsupported decorated constructor type" )
@@ -118,7 +119,7 @@ def format(self, *args: object, **kwargs: object) -> "ErrorMessage":
118
119
MALFORMED_ASSERT : Final = ErrorMessage ("Assertion is always true, perhaps remove parentheses?" )
119
120
DUPLICATE_TYPE_SIGNATURES : Final = ErrorMessage ("Function has duplicate type signatures" )
120
121
DESCRIPTOR_SET_NOT_CALLABLE : Final = ErrorMessage ("{}.__set__ is not callable" )
121
- DESCRIPTOR_GET_NOT_CALLABLE : Final = "{}.__get__ is not callable"
122
+ DESCRIPTOR_GET_NOT_CALLABLE : Final = ErrorMessage ( "{}.__get__ is not callable" )
122
123
MODULE_LEVEL_GETATTRIBUTE : Final = ErrorMessage (
123
124
"__getattribute__ is not valid at the module level"
124
125
)
@@ -140,29 +141,43 @@ def format(self, *args: object, **kwargs: object) -> "ErrorMessage":
140
141
code = codes .TRUTHY_BOOL ,
141
142
)
142
143
NOT_CALLABLE : Final = '{} not callable'
143
- PYTHON2_PRINT_FILE_TYPE : Final = (
144
+ PYTHON2_PRINT_FILE_TYPE : Final = ErrorMessage (
144
145
'Argument "file" to "print" has incompatible type "{}"; expected "{}"'
145
146
)
147
+ ENUM_EXTEND_EXISTING_MEMBERS : Final = ErrorMessage (
148
+ 'Cannot extend enum with existing members: "{}"'
149
+ )
146
150
147
151
# Generic
148
- GENERIC_INSTANCE_VAR_CLASS_ACCESS : Final = (
152
+ GENERIC_INSTANCE_VAR_CLASS_ACCESS : Final = ErrorMessage (
149
153
"Access to generic instance variables via class is ambiguous"
150
154
)
151
- GENERIC_CLASS_VAR_ACCESS : Final = "Access to generic class variables is ambiguous"
155
+ GENERIC_CLASS_VAR_ACCESS : Final = ErrorMessage ( "Access to generic class variables is ambiguous" )
152
156
BARE_GENERIC : Final = ErrorMessage ("Missing type parameters for generic type {}" , codes .TYPE_ARG )
153
157
IMPLICIT_GENERIC_ANY_BUILTIN : Final = ErrorMessage (
154
158
'Implicit generic "Any". Use "{}" and specify generic parameters' , codes .TYPE_ARG
155
159
)
156
160
157
161
# TypeVar
158
- INCOMPATIBLE_TYPEVAR_VALUE : Final = 'Value of type variable "{}" of {} cannot be {}'
159
- CANNOT_USE_TYPEVAR_AS_EXPRESSION : Final = 'Type variable "{}.{}" cannot be used as an expression'
160
- INVALID_TYPEVAR_AS_TYPEARG : Final = 'Type variable "{}" not valid as type argument value for "{}"'
161
- INVALID_TYPEVAR_ARG_BOUND : Final = 'Type argument {} of "{}" must be a subtype of {}'
162
- INVALID_TYPEVAR_ARG_VALUE : Final = 'Invalid type argument value for "{}"'
162
+ INCOMPATIBLE_TYPEVAR_VALUE : Final = ErrorMessage (
163
+ 'Value of type variable "{}" of {} cannot be {}' , codes .TYPE_VAR
164
+ )
165
+ CANNOT_USE_TYPEVAR_AS_EXPRESSION : Final = ErrorMessage (
166
+ 'Type variable "{}.{}" cannot be used as an expression'
167
+ )
168
+ INVALID_TYPEVAR_AS_TYPEARG : Final = ErrorMessage (
169
+ 'Type variable "{}" not valid as type argument value for "{}"' , codes .TYPE_VAR
170
+ )
171
+ INVALID_TYPEVAR_ARG_BOUND : Final = ErrorMessage (
172
+ 'Type argument {} of "{}" must be a subtype of {}' , codes .TYPE_VAR
173
+ )
174
+ INVALID_TYPEVAR_ARG_VALUE : Final = ErrorMessage (
175
+ 'Invalid type argument value for "{}"' , codes .TYPE_VAR
176
+ )
163
177
TYPEVAR_VARIANCE_DEF : Final = ErrorMessage ('TypeVar "{}" may only be a literal bool' )
164
178
TYPEVAR_BOUND_MUST_BE_TYPE : Final = ErrorMessage ('TypeVar "bound" must be a type' )
165
179
TYPEVAR_UNEXPECTED_ARGUMENT : Final = ErrorMessage ('Unexpected argument to "TypeVar()"' )
180
+ PARAMSPEC_INVALID_LOCATION : Final = ErrorMessage ('Invalid location for ParamSpec "{}"' )
166
181
167
182
# FastParse
168
183
TYPE_COMMENT_SYNTAX_ERROR_VALUE : Final = ErrorMessage (
@@ -1031,7 +1046,7 @@ def format(self, *args: object, **kwargs: object) -> "ErrorMessage":
1031
1046
DEPENDENT_FINAL_IN_CLASS_BODY : Final = ErrorMessage (
1032
1047
"Final name declared in class body cannot depend on type variables"
1033
1048
)
1034
- CANNOT_ACCESS_FINAL_INSTANCE_ATTR : Final = (
1049
+ CANNOT_ACCESS_FINAL_INSTANCE_ATTR : Final = ErrorMessage (
1035
1050
'Cannot access final instance attribute "{}" on class object'
1036
1051
)
1037
1052
CANNOT_MAKE_DELETABLE_FINAL : Final = ErrorMessage ("Deletable attribute cannot be final" )
@@ -1062,19 +1077,23 @@ def format(self, *args: object, **kwargs: object) -> "ErrorMessage":
1062
1077
TYPE_GUARD_POS_ARG_REQUIRED : Final = ErrorMessage ("Type guard requires positional argument" )
1063
1078
1064
1079
# Match Statement
1065
- MISSING_MATCH_ARGS : Final = 'Class "{}" doesn\' t define "__match_args__"'
1066
- OR_PATTERN_ALTERNATIVE_NAMES : Final = "Alternative patterns bind different names"
1067
- CLASS_PATTERN_GENERIC_TYPE_ALIAS : Final = (
1080
+ MISSING_MATCH_ARGS : Final = ErrorMessage ( 'Class "{}" doesn\' t define "__match_args__"' )
1081
+ OR_PATTERN_ALTERNATIVE_NAMES : Final = ErrorMessage ( "Alternative patterns bind different names" )
1082
+ CLASS_PATTERN_GENERIC_TYPE_ALIAS : Final = ErrorMessage (
1068
1083
"Class pattern class must not be a type alias with type parameters"
1069
1084
)
1070
- CLASS_PATTERN_TYPE_REQUIRED : Final = 'Expected type in class pattern; found "{}"'
1071
- CLASS_PATTERN_TOO_MANY_POSITIONAL_ARGS : Final = "Too many positional patterns for class pattern"
1072
- CLASS_PATTERN_KEYWORD_MATCHES_POSITIONAL : Final = (
1085
+ CLASS_PATTERN_TYPE_REQUIRED : Final = ErrorMessage ('Expected type in class pattern; found "{}"' )
1086
+ CLASS_PATTERN_TOO_MANY_POSITIONAL_ARGS : Final = ErrorMessage (
1087
+ "Too many positional patterns for class pattern"
1088
+ )
1089
+ CLASS_PATTERN_KEYWORD_MATCHES_POSITIONAL : Final = ErrorMessage (
1073
1090
'Keyword "{}" already matches a positional pattern'
1074
1091
)
1075
- CLASS_PATTERN_DUPLICATE_KEYWORD_PATTERN : Final = 'Duplicate keyword pattern "{}"'
1076
- CLASS_PATTERN_UNKNOWN_KEYWORD : Final = 'Class "{}" has no attribute "{}"'
1077
- MULTIPLE_ASSIGNMENTS_IN_PATTERN : Final = 'Multiple assignments to name "{}" in pattern'
1092
+ CLASS_PATTERN_DUPLICATE_KEYWORD_PATTERN : Final = ErrorMessage ('Duplicate keyword pattern "{}"' )
1093
+ CLASS_PATTERN_UNKNOWN_KEYWORD : Final = ErrorMessage ('Class "{}" has no attribute "{}"' )
1094
+ MULTIPLE_ASSIGNMENTS_IN_PATTERN : Final = ErrorMessage (
1095
+ 'Multiple assignments to name "{}" in pattern'
1096
+ )
1078
1097
1079
1098
# Plugin: attrs
1080
1099
CANNOT_DETERMINE_INIT_TYPE : Final = ErrorMessage ("Cannot determine __init__ type from converter" )
@@ -1149,7 +1168,3 @@ def format(self, *args: object, **kwargs: object) -> "ErrorMessage":
1149
1168
"Never apply isinstance() to unexpanded types; use mypy.types.get_proper_type() first"
1150
1169
)
1151
1170
REDUNDANT_GET_PROPER_TYPE : Final = ErrorMessage ("Redundant call to get_proper_type()" )
1152
-
1153
-
1154
- # test-data/type_anal_hook.py
1155
- INVALID_SIGNAL_TYPE : Final = ErrorMessage ('Invalid "Signal" type (expected "Signal[[t, ...]]")' )
0 commit comments