alecthomas / alecthomas/voluptuous

"AtLeastOne" dict Key Validator

Offen
#126 12 Kommentare 6 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

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`.

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.