Skip to content

Commit

Permalink
Add error code to missed invalid Literal case (#13763)
Browse files Browse the repository at this point in the history
  • Loading branch information
hauntsaninja committed Sep 29, 2022
1 parent 3015abf commit d560570
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions mypy/typeanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -1250,7 +1250,11 @@ def analyze_literal_param(self, idx: int, arg: Type, ctx: Context) -> list[Type]
# TODO: Once we start adding support for enums, make sure we report a custom
# error for case 2 as well.
if arg.type_of_any not in (TypeOfAny.from_error, TypeOfAny.special_form):
self.fail(f'Parameter {idx} of Literal[...] cannot be of type "Any"', ctx)
self.fail(
f'Parameter {idx} of Literal[...] cannot be of type "Any"',
ctx,
code=codes.VALID_TYPE,
)
return None
elif isinstance(arg, RawExpressionType):
# A raw literal. Convert it directly into a literal if we can.
Expand Down Expand Up @@ -1284,7 +1288,7 @@ def analyze_literal_param(self, idx: int, arg: Type, ctx: Context) -> list[Type]
out.extend(union_result)
return out
else:
self.fail(f"Parameter {idx} of Literal[...] is invalid", ctx)
self.fail(f"Parameter {idx} of Literal[...] is invalid", ctx, code=codes.VALID_TYPE)
return None

def analyze_type(self, t: Type) -> Type:
Expand Down

0 comments on commit d560570

Please sign in to comment.