Skip to content

Commit

Permalink
Improve misleading message in Enum() (#5317) (#14590)
Browse files Browse the repository at this point in the history
Clarifying this is a mypy limitation, not an Enum() requirement

Not a true fix, but a workaround for #5317 to avoid confusion (as seen
by the many duplicates)
  • Loading branch information
MestreLion authored Feb 2, 2023
1 parent 0929773 commit 50717cf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
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"
"Second argument of %s() must be string, tuple, list or dict literal for mypy to determine Enum members"
% 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"
"Second argument of %s() must be string, tuple, list or dict literal for mypy to determine Enum members"
% 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: Second argument of Enum() must be string, tuple, list or dict literal for mypy to determine Enum members
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: Second argument of Enum() must be string, tuple, list or dict literal for mypy to determine Enum members
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: Second argument of Enum() must be string, tuple, list or dict literal for mypy to determine Enum members
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: Second argument of IntEnum() must be string, tuple, list or dict literal for mypy to determine Enum members
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

0 comments on commit 50717cf

Please sign in to comment.