Skip to content
Merged
Show file tree
Hide file tree
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
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,25 @@ in the schema list is compared to each value in the input data:

```

However, an empty list (`[]`) is treated as is. If you want to specify a list that can
contain anything, specify it as `list`:

```pycon
>>> schema = Schema([])
>>> schema([1]) # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
...
MultipleInvalid: not a valid value
>>> schema([])
[]
>>> schema = Schema(list)
>>> schema([])
[]
>>> schema([1, 2])
[1, 2]

```

### Validation functions

Validators are simple callables that raise an `Invalid` exception when
Expand Down
2 changes: 1 addition & 1 deletion voluptuous/schema_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def _compile(self, schema):
return self._compile_object(schema)
if isinstance(schema, collections.Mapping):
return self._compile_dict(schema)
elif isinstance(schema, list):
elif isinstance(schema, list) and len(schema):
return self._compile_list(schema)
elif isinstance(schema, tuple):
return self._compile_tuple(schema)
Expand Down
6 changes: 6 additions & 0 deletions voluptuous/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,3 +479,9 @@ def test_unordered():
assert_raises(Invalid, s, [3, 2])
s = Schema(Unordered([3, int]))
s([3, 2])


def test_empty_list_as_exact():
s = Schema([])
assert_raises(Invalid, s, [1])
s([])