Skip to content
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

Improve misleading message in Enum() (#5317) #14590

Merged
merged 3 commits into from
Feb 2, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 2 additions & 2 deletions mypy/semanal_enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,14 @@ def parse_enum_call_args(
items.append(field)
else:
return self.fail_enum_call_arg(
"%s() expects a string, tuple, list or dict literal as the second argument"
"Non-literal string, tuple, list or dict as the second argument of %s() is not supported"
% class_name,
call,
)
else:
# TODO: Allow dict(x=1, y=2) as a substitute for {'x': 1, 'y': 2}?
return self.fail_enum_call_arg(
"%s() expects a string, tuple, list or dict literal as the second argument"
"Non-literal string, tuple, list or dict as the second argument of %s() is not supported"
% class_name,
call,
)
Expand Down
8 changes: 4 additions & 4 deletions test-data/unit/check-enum.test
Original file line number Diff line number Diff line change
Expand Up @@ -482,13 +482,13 @@ W.c
[typing fixtures/typing-medium.pyi]
[out]
main:2: error: Too few arguments for Enum()
main:3: error: Enum() expects a string, tuple, list or dict literal as the second argument
main:3: error: Non-literal string, tuple, list or dict as the second argument of Enum() is not supported
main:4: error: Too many arguments for Enum()
main:5: error: Enum() expects a string, tuple, list or dict literal as the second argument
main:5: error: Non-literal string, tuple, list or dict as the second argument of Enum() is not supported
main:5: error: Name "foo" is not defined
main:7: error: Enum() expects a string, tuple, list or dict literal as the second argument
main:7: error: Non-literal string, tuple, list or dict as the second argument of Enum() is not supported
main:8: error: Too few arguments for IntEnum()
main:9: error: IntEnum() expects a string, tuple, list or dict literal as the second argument
main:9: error: Non-literal string, tuple, list or dict as the second argument of IntEnum() is not supported
main:10: error: Too many arguments for IntEnum()
main:11: error: Enum() needs at least one item
main:12: error: Enum() needs at least one item
Expand Down