Skip to content

Commit d560570

Browse files
authored
Add error code to missed invalid Literal case (#13763)
1 parent 3015abf commit d560570

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

mypy/typeanal.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -1250,7 +1250,11 @@ def analyze_literal_param(self, idx: int, arg: Type, ctx: Context) -> list[Type]
12501250
# TODO: Once we start adding support for enums, make sure we report a custom
12511251
# error for case 2 as well.
12521252
if arg.type_of_any not in (TypeOfAny.from_error, TypeOfAny.special_form):
1253-
self.fail(f'Parameter {idx} of Literal[...] cannot be of type "Any"', ctx)
1253+
self.fail(
1254+
f'Parameter {idx} of Literal[...] cannot be of type "Any"',
1255+
ctx,
1256+
code=codes.VALID_TYPE,
1257+
)
12541258
return None
12551259
elif isinstance(arg, RawExpressionType):
12561260
# A raw literal. Convert it directly into a literal if we can.
@@ -1284,7 +1288,7 @@ def analyze_literal_param(self, idx: int, arg: Type, ctx: Context) -> list[Type]
12841288
out.extend(union_result)
12851289
return out
12861290
else:
1287-
self.fail(f"Parameter {idx} of Literal[...] is invalid", ctx)
1291+
self.fail(f"Parameter {idx} of Literal[...] is invalid", ctx, code=codes.VALID_TYPE)
12881292
return None
12891293

12901294
def analyze_type(self, t: Type) -> Type:

0 commit comments

Comments
 (0)