Skip to content

Return default from the validation function #234

@ldv1

Description

@ldv1

Hi,

I defined my own validation function:

def is_mytype(value,*options):
            …

and so

val = Validator({'mytype': is_mytype })

In the spec file I have

key = mytype(“john”,”jack”,”patrick”,default=list(“john”))

If the value of this key is missing or “” in the configuration file, then an error is raised.
Only if the key is missing, then it is set to the default, here key = [ “john” ]

I would like to return in my validation function the default if value is empty, e.g.

def is_mytype(value,*options):
            if not value:
                        return default
            ...

How could I do that ?
Or is it possible that the default be returned if the value is missing in the configuration file or "" ?
Thanks for the help!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions