alecthomas / alecthomas/voluptuous

erroneous processing of nested iterables

Ouverte
#142 6 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
Langage dominant
Python
Étoiles
1.9k
Forks
237
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

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.

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.