8000 "AtLeastOne" dict Key Validator · Issue #126 · alecthomas/voluptuous · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
"AtLeastOne" dict Key Validator #126
Open
@kennytrytek-wf

Description

@kennytrytek-wf

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0