Skip to content

Add error code to missed invalid Literal case #13763

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 29, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't comment there, but should the error on line 1253 above also have this code?

return None

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