alecthomas / alecthomas/voluptuous

"AtLeastOne" dict Key Validator

Abierto
#126 12 comentarios 6 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
Python
Estrellas
1.9k
Forks
237
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

I want to be able to create a Schema with this idea:

```
s = Schema({
AtLeastOne('onetwo', 'group1'): Any(1, 2, None),
AtLeastOne('threefour', 'group1'): Any(3, 4, None),
'abc': 'abc'})

>>> s({'abc': 'abc'})
AtLeastOneInvalid: 'group1' must specify at least one of ['onetwo', 'threefour']

>>> s({'onetwo': 3, 'abc': 'abc'})
MultipleInvalid: not a valid value for dictionary value @ data['onetwo']

>>> s({'onetwo': 2, 'abc': 'abc'})
{'onetwo': 2, 'abc': 'abc'}

>>> s({'threefour': 4, 'abc': 'abc'})
{'threefour': 4, 'abc': 'abc'}

>>> s({'onetwo': 1, 'threefour': 3, 'abc': 'abc'})
{'onetwo': 1, 'threefour': 3, 'abc': 'abc'}
```

This completes the functionality started with the addition of `Exclusive` and `Inclusive`.

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.