Skip to content

Commit

Permalink
Display valid Enum values in Coerce
Browse files Browse the repository at this point in the history
  • Loading branch information
epenet committed Mar 8, 2022
1 parent 980a55f commit 77f08f2
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions voluptuous/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import sys
from functools import wraps
from decimal import Decimal, InvalidOperation
from enum import Enum

from voluptuous.schema_builder import Schema, raises, message
from voluptuous.error import (MultipleInvalid, CoerceInvalid, TrueInvalid, FalseInvalid, BooleanInvalid, Invalid,
Expand Down Expand Up @@ -95,6 +96,8 @@ def __call__(self, v):
return self.type(v)
except (ValueError, TypeError, InvalidOperation):
msg = self.msg or ('expected %s' % self.type_name)
if not self.msg and issubclass(self.type, Enum):
msg += " or one of %s" % [e.value for e in self.type]
raise CoerceInvalid(msg)

def __repr__(self):
Expand Down

0 comments on commit 77f08f2

Please sign in to comment.