Skip to content

Commit

Permalink
fixed naming and quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
David Montague committed Jun 23, 2019
1 parent 114c70b commit c5ac4e7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions pydantic/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,14 +346,14 @@ def callable_validator(v: Any) -> AnyCallable:

def make_literal_validator(type_: Any) -> Callable[[Any], Any]:
if sys.version_info >= (3, 7):
allowed_choices = type_.__args__
permitted_choices = type_.__args__
else:
allowed_choices = type_.__values__
allowed_choices_set = set(allowed_choices)
permitted_choices = type_.__values__
allowed_choices_set = set(permitted_choices)

def literal_validator(v: Any) -> Any:
if v not in allowed_choices_set:
raise errors.WrongConstantError(given=v, permitted=allowed_choices)
raise errors.WrongConstantError(given=v, permitted=permitted_choices)
return v

return literal_validator
Expand Down
4 changes: 2 additions & 2 deletions tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -1679,7 +1679,7 @@ class Model(BaseModel):
assert exc_info.value.errors() == [
{
'loc': ('a',),
'msg': 'unexpected value; permitted: \'a\'',
'msg': "unexpected value; permitted: 'a'",
'type': 'value_error.const',
'ctx': {'given': 'b', 'permitted': ('a',)},
}
Expand All @@ -1698,7 +1698,7 @@ class Model(BaseModel):
assert exc_info.value.errors() == [
{
'loc': ('a_or_b',),
'msg': 'unexpected value; permitted: \'a\', \'b\'',
'msg': "unexpected value; permitted: 'a', 'b'",
'type': 'value_error.const',
'ctx': {'given': 'c', 'permitted': ('a', 'b')},
}
Expand Down

0 comments on commit c5ac4e7

Please sign in to comment.