Skip to content

Commit 65ede8d

Browse files
Update errorcodes.py: harmonize all of the type annotations
This completes an in-line todo, and removes code with no downside.
1 parent d27b43b commit 65ede8d

File tree

1 file changed

+24
-27
lines changed

1 file changed

+24
-27
lines changed

mypy/errorcodes.py

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ def __hash__(self) -> int:
5252

5353
ATTR_DEFINED: Final = ErrorCode("attr-defined", "Check that attribute exists", "General")
5454
NAME_DEFINED: Final = ErrorCode("name-defined", "Check that name is defined", "General")
55-
CALL_ARG: Final[ErrorCode] = ErrorCode(
55+
CALL_ARG: Final = ErrorCode(
5656
"call-arg", "Check number, names and kinds of arguments in calls", "General"
5757
)
5858
ARG_TYPE: Final = ErrorCode("arg-type", "Check argument types in calls", "General")
5959
CALL_OVERLOAD: Final = ErrorCode(
6060
"call-overload", "Check that an overload variant matches arguments", "General"
6161
)
62-
VALID_TYPE: Final[ErrorCode] = ErrorCode(
62+
VALID_TYPE: Final = ErrorCode(
6363
"valid-type", "Check that type (annotation) is valid", "General"
6464
)
6565
VAR_ANNOTATED: Final = ErrorCode(
@@ -68,16 +68,16 @@ def __hash__(self) -> int:
6868
OVERRIDE: Final = ErrorCode(
6969
"override", "Check that method override is compatible with base class", "General"
7070
)
71-
RETURN: Final[ErrorCode] = ErrorCode(
71+
RETURN: Final = ErrorCode(
7272
"return", "Check that function always returns a value", "General"
7373
)
74-
RETURN_VALUE: Final[ErrorCode] = ErrorCode(
74+
RETURN_VALUE: Final = ErrorCode(
7575
"return-value", "Check that return value is compatible with signature", "General"
7676
)
77-
ASSIGNMENT: Final[ErrorCode] = ErrorCode(
77+
ASSIGNMENT: Final = ErrorCode(
7878
"assignment", "Check that assigned value is compatible with target", "General"
7979
)
80-
METHOD_ASSIGN: Final[ErrorCode] = ErrorCode(
80+
METHOD_ASSIGN: Final = ErrorCode(
8181
"method-assign",
8282
"Check that assignment target is not a method",
8383
"General",
@@ -143,9 +143,7 @@ def __hash__(self) -> int:
143143
UNUSED_COROUTINE: Final = ErrorCode(
144144
"unused-coroutine", "Ensure that all coroutines are used", "General"
145145
)
146-
# TODO: why do we need the explicit type here? Without it mypyc CI builds fail with
147-
# mypy/message_registry.py:37: error: Cannot determine type of "EMPTY_BODY" [has-type]
148-
EMPTY_BODY: Final[ErrorCode] = ErrorCode(
146+
EMPTY_BODY: Final = ErrorCode(
149147
"empty-body",
150148
"A dedicated error code to opt out return errors for empty/trivial bodies",
151149
"General",
@@ -160,7 +158,7 @@ def __hash__(self) -> int:
160158
"await-not-async", 'Warn about "await" outside coroutine ("async def")', "General"
161159
)
162160
# These error codes aren't enabled by default.
163-
NO_UNTYPED_DEF: Final[ErrorCode] = ErrorCode(
161+
NO_UNTYPED_DEF: Final= ErrorCode(
164162
"no-untyped-def", "Check that every function has an annotation", "General"
165163
)
166164
NO_UNTYPED_CALL: Final = ErrorCode(
@@ -186,13 +184,13 @@ def __hash__(self) -> int:
186184
UNREACHABLE: Final = ErrorCode(
187185
"unreachable", "Warn about unreachable statements or expressions", "General"
188186
)
189-
ANNOTATION_UNCHECKED = ErrorCode(
187+
ANNOTATION_UNCHECKED: Final = ErrorCode(
190188
"annotation-unchecked", "Notify about type annotations in unchecked functions", "General"
191189
)
192-
TYPEDDICT_READONLY_MUTATED = ErrorCode(
190+
TYPEDDICT_READONLY_MUTATED: Final = ErrorCode(
193191
"typeddict-readonly-mutated", "TypedDict's ReadOnly key is mutated", "General"
194192
)
195-
POSSIBLY_UNDEFINED: Final[ErrorCode] = ErrorCode(
193+
POSSIBLY_UNDEFINED: Final = ErrorCode(
196194
"possibly-undefined",
197195
"Warn about variables that are defined only in some execution paths",
198196
"General",
@@ -201,18 +199,18 @@ def __hash__(self) -> int:
201199
REDUNDANT_EXPR: Final = ErrorCode(
202200
"redundant-expr", "Warn about redundant expressions", "General", default_enabled=False
203201
)
204-
TRUTHY_BOOL: Final[ErrorCode] = ErrorCode(
202+
TRUTHY_BOOL: Final = ErrorCode(
205203
"truthy-bool",
206204
"Warn about expressions that could always evaluate to true in boolean contexts",
207205
"General",
208206
default_enabled=False,
209207
)
210-
TRUTHY_FUNCTION: Final[ErrorCode] = ErrorCode(
208+
TRUTHY_FUNCTION: Final = ErrorCode(
211209
"truthy-function",
212210
"Warn about function that always evaluate to true in boolean contexts",
213211
"General",
214212
)
215-
TRUTHY_ITERABLE: Final[ErrorCode] = ErrorCode(
213+
TRUTHY_ITERABLE: Final = ErrorCode(
216214
"truthy-iterable",
217215
"Warn about Iterable expressions that could always evaluate to true in boolean contexts",
218216
"General",
@@ -238,13 +236,13 @@ def __hash__(self) -> int:
238236
"General",
239237
default_enabled=False,
240238
)
241-
REDUNDANT_SELF_TYPE = ErrorCode(
239+
REDUNDANT_SELF_TYPE: Final = ErrorCode(
242240
"redundant-self",
243241
"Warn about redundant Self type annotations on method first argument",
244242
"General",
245243
default_enabled=False,
246244
)
247-
USED_BEFORE_DEF: Final[ErrorCode] = ErrorCode(
245+
USED_BEFORE_DEF: Final = ErrorCode(
248246
"used-before-def", "Warn about variables that are used before they are defined", "General"
249247
)
250248
UNUSED_IGNORE: Final = ErrorCode(
@@ -262,7 +260,7 @@ def __hash__(self) -> int:
262260
"General",
263261
default_enabled=False,
264262
)
265-
MUTABLE_OVERRIDE: Final[ErrorCode] = ErrorCode(
263+
MUTABLE_OVERRIDE: Final = ErrorCode(
266264
"mutable-override",
267265
"Reject covariant overrides for mutable attributes",
268266
"General",
@@ -274,42 +272,41 @@ def __hash__(self) -> int:
274272
"General",
275273
default_enabled=False,
276274
)
277-
METACLASS: Final[ErrorCode] = ErrorCode("metaclass", "Ensure that metaclass is valid", "General")
275+
METACLASS: Final = ErrorCode("metaclass", "Ensure that metaclass is valid", "General")
278276

279277
# Syntax errors are often blocking.
280-
SYNTAX: Final[ErrorCode] = ErrorCode("syntax", "Report syntax errors", "General")
278+
SYNTAX: Final = ErrorCode("syntax", "Report syntax errors", "General")
281279

282280
# This is an internal marker code for a whole-file ignore. It is not intended to
283281
# be user-visible.
284282
FILE: Final = ErrorCode("file", "Internal marker for a whole file being ignored", "General")
285283
del error_codes[FILE.code]
286284

287285
# This is a catch-all for remaining uncategorized errors.
288-
MISC: Final[ErrorCode] = ErrorCode("misc", "Miscellaneous other checks", "General")
286+
MISC: Final = ErrorCode("misc", "Miscellaneous other checks", "General")
289287

290-
OVERLOAD_CANNOT_MATCH: Final[ErrorCode] = ErrorCode(
288+
OVERLOAD_CANNOT_MATCH: Final = ErrorCode(
291289
"overload-cannot-match",
292290
"Warn if an @overload signature can never be matched",
293291
"General",
294292
sub_code_of=MISC,
295293
)
296294

297-
298-
OVERLOAD_OVERLAP: Final[ErrorCode] = ErrorCode(
295+
OVERLOAD_OVERLAP: Final = ErrorCode(
299296
"overload-overlap",
300297
"Warn if multiple @overload variants overlap in unsafe ways",
301298
"General",
302299
sub_code_of=MISC,
303300
)
304301

305-
PROPERTY_DECORATOR = ErrorCode(
302+
PROPERTY_DECORATOR: Final = ErrorCode(
306303
"prop-decorator",
307304
"Decorators on top of @property are not supported",
308305
"General",
309306
sub_code_of=MISC,
310307
)
311308

312-
NARROWED_TYPE_NOT_SUBTYPE: Final[ErrorCode] = ErrorCode(
309+
NARROWED_TYPE_NOT_SUBTYPE: Final = ErrorCode(
313310
"narrowed-type-not-subtype",
314311
"Warn if a TypeIs function's narrowed type is not a subtype of the original type",
315312
"General",

0 commit comments

Comments
 (0)