Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return default from the validation function #234

Open
ldv1 opened this issue Mar 10, 2023 · 0 comments
Open

Return default from the validation function #234

ldv1 opened this issue Mar 10, 2023 · 0 comments

Comments

@ldv1
Copy link

ldv1 commented Mar 10, 2023

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant