Skip to content

Commit

Permalink
Make Schema([]) usage consistent with Schema({})
Browse files Browse the repository at this point in the history
Validation on an empty list was not raising any exception when given values
but an empty dict was. Make it uniform and make them both raise a
MultipleInvalid exception on unwanted values.
  • Loading branch information
tbillon authored and alecthomas committed Nov 2, 2017
1 parent 74f5a34 commit 95489bd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ contain anything, specify it as `list`:
... raise AssertionError('MultipleInvalid not raised')
... except MultipleInvalid as e:
... exc = e
>>> str(exc) == "not a valid value"
>>> str(exc) == "not a valid value @ data[1]"
True
>>> schema([])
[]
Expand Down
6 changes: 5 additions & 1 deletion voluptuous/schema_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def _compile(self, schema):
return self._compile_object(schema)
if isinstance(schema, collections.Mapping):
return self._compile_dict(schema)
elif isinstance(schema, list) and len(schema):
elif isinstance(schema, list):
return self._compile_list(schema)
elif isinstance(schema, tuple):
return self._compile_tuple(schema)
Expand Down Expand Up @@ -551,6 +551,10 @@ def validate_sequence(path, data):

# Empty seq schema, allow any data.
if not schema:
if data:
raise er.MultipleInvalid([
er.ValueInvalid('not a valid value', [value]) for value in data
])
return data

out = []
Expand Down

0 comments on commit 95489bd

Please sign in to comment.