Skip to content

Commit 50717cf

Browse files
authored
Improve misleading message in Enum() (#5317) (#14590)
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)
1 parent 0929773 commit 50717cf

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

mypy/semanal_enum.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,14 +220,14 @@ def parse_enum_call_args(
220220
items.append(field)
221221
else:
222222
return self.fail_enum_call_arg(
223-
"%s() expects a string, tuple, list or dict literal as the second argument"
223+
"Second argument of %s() must be string, tuple, list or dict literal for mypy to determine Enum members"
224224
% class_name,
225225
call,
226226
)
227227
else:
228228
# TODO: Allow dict(x=1, y=2) as a substitute for {'x': 1, 'y': 2}?
229229
return self.fail_enum_call_arg(
230-
"%s() expects a string, tuple, list or dict literal as the second argument"
230+
"Second argument of %s() must be string, tuple, list or dict literal for mypy to determine Enum members"
231231
% class_name,
232232
call,
233233
)

test-data/unit/check-enum.test

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -482,13 +482,13 @@ W.c
482482
[typing fixtures/typing-medium.pyi]
483483
[out]
484484
main:2: error: Too few arguments for Enum()
485-
main:3: error: Enum() expects a string, tuple, list or dict literal as the second argument
485+
main:3: error: Second argument of Enum() must be string, tuple, list or dict literal for mypy to determine Enum members
486486
main:4: error: Too many arguments for Enum()
487-
main:5: error: Enum() expects a string, tuple, list or dict literal as the second argument
487+
main:5: error: Second argument of Enum() must be string, tuple, list or dict literal for mypy to determine Enum members
488488
main:5: error: Name "foo" is not defined
489-
main:7: error: Enum() expects a string, tuple, list or dict literal as the second argument
489+
main:7: error: Second argument of Enum() must be string, tuple, list or dict literal for mypy to determine Enum members
490490
main:8: error: Too few arguments for IntEnum()
491-
main:9: error: IntEnum() expects a string, tuple, list or dict literal as the second argument
491+
main:9: error: Second argument of IntEnum() must be string, tuple, list or dict literal for mypy to determine Enum members
492492
main:10: error: Too many arguments for IntEnum()
493493
main:11: error: Enum() needs at least one item
494494
main:12: error: Enum() needs at least one item

0 commit comments

Comments
 (0)