Skip to content
Closed
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
9 changes: 9 additions & 0 deletions Lib/enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -1218,6 +1218,15 @@ def __new__(cls, value):
else:
ve_exc = ValueError("%r is not a valid %s" % (value, cls.__qualname__))
if result is None and exc is None:
# If `_missing_` has not been overridden, augment the
# default error message with the list of valid values to
# save users from having to inspect ``cls.__members__``.
if cls._missing_.__func__ is Enum._missing_.__func__:
valid_values = ", ".join(repr(m._value_) for m in cls)
if valid_values:
ve_exc = ValueError(
"%r is not a valid %s. Valid values: %s"
% (value, cls.__qualname__, valid_values))
raise ve_exc
elif exc is None:
exc = TypeError(
Expand Down
Loading