alecthomas / alecthomas/voluptuous

erroneous processing of nested iterables

Offen
#142 6 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Python
Sterne
1.9k
Forks
237
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

Related to the discussion in https://github.com/alecthomas/voluptuous/pull/141. See https://github.com/alecthomas/voluptuous/pull/141#issuecomment-167267024 in particular.
### Version

```
$ pip list | grep voluptuous
voluptuous (0.8.8)
```

Voluptuous seems to get confused by nested iterables. To demonstrate, I'll use a list of dictionaries.

``` pycon
>>> from voluptuous import *
>>> data = [{1: 'one'}, {2: 'two'}]
```
### Case 0: a list of dictionaries

I would expect this to work as is.

``` pycon
>>> schema = Schema([{1: str}, {2: str}])
>>> schema(data)
Traceback (most recent call last):
File "", line 1, in
File "/usr/lib64/python3.4/site-packages/voluptuous.py", line 337, in __call__
return self._compiled([], data)
File "/usr/lib64/python3.4/site-packages/voluptuous.py", line 672, in validate_sequence
cval = validate(index_path, value)
File "/usr/lib64/python3.4/site-packages/voluptuous.py", line 635, in validate_dict
return base_validate(path, iteritems(data), out)
File "/usr/lib64/python3.4/site-packages/voluptuous.py", line 471, in validate_mapping
raise MultipleInvalid(errors)
voluptuous.MultipleInvalid: extra keys not allowed @ data[1][2]
```
### Case 1: the first dictionary has the invalid value

This case correctly finds the true error before getting distracted by the other dictionary.

``` pycon
>>> schema = Schema([{1: bool}, {2: str}])
>>> schema(data)
Traceback (most recent call last):
File "", line 1, in
File "/usr/lib64/python3.4/site-packages/voluptuous.py", line 337, in __call__
return self._compiled([], data)
File "/usr/lib64/python3.4/site-packages/voluptuous.py", line 672, in validate_sequence
cval = validate(index_path, value)
File "/usr/lib64/python3.4/site-packages/voluptuous.py", line 635, in validate_dict
return base_validate(path, iteritems(data), out)
File "/usr/lib64/python3.4/site-packages/voluptuous.py", line 471, in validate_mapping
raise MultipleInvalid(errors)
voluptuous.MultipleInvalid: expected bool for dictionary value @ data[0][1]
```
### Case 2: the second dictionary has the invalid value

Whereas this case does not.

``` pycon
>>> schema = Schema([{1: str}, {2: bool}])
>>> schema(data)
Traceback (most recent call last):
File "", line 1, in
File "/usr/lib64/python3.4/site-packages/voluptuous.py", line 337, in __call__
return self._compiled([], data)
File "/usr/lib64/python3.4/site-packages/voluptuous.py", line 672, in validate_sequence
cval = validate(index_path, value)
File "/usr/lib64/python3.4/site-packages/voluptuous.py", line 635, in validate_dict
return base_validate(path, iteritems(data), out)
File "/usr/lib64/python3.4/site-packages/voluptuous.py", line 471, in validate_mapping
raise MultipleInvalid(errors)
voluptuous.MultipleInvalid: extra keys not allowed @ data[1][2]
```

I will likely try to find time to work on this in the next few days, but if anyone else may know how to fix this, I would be glad for the help.

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.