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

Allow a discrminant field in validators #368

Merged
merged 5 commits into from
Aug 15, 2019

Conversation

ydidwania
Copy link
Contributor

@ydidwania ydidwania commented Nov 30, 2018

Attempts to fix #360
The accepted solution was to add a Union type which requires a discriminant. What I have done is check for a discrminant argument, and run the value and alternatives through the discriminant function to obtain a filtered list of alternatives. This allows a discriminant field to be included in the existing types

Since the validators are compiled before execution, when using the _WithSubValidators class, and the value is available during execution I cannot check if it is accepted by the discriminant or not any earlier than execution. In such a case I'd have to recompile the validators obtained from the discriminant.

I have a bunch of print statements committed which I will remove once this is approved.

@djmitche
Copy link

@alecthomas did you want to comment on this?

@alecthomas
Copy link
Owner

It's hard to tell as the doctest doesn't actually test it?

"""Use the first validated value among those selected by discrminant.

:param msg: Message to deliver to user if validation fails.
:param discriminant: Function to filter the values
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move the signature description into this param comment please.

@alecthomas alecthomas merged commit f5e64dd into alecthomas:master Aug 15, 2019
@alecthomas
Copy link
Owner

Thanks!

@halbow
Copy link

halbow commented Mar 9, 2020

HI @alecthomas !

I saw that this repo is contributions only, but will you still make release from master from time to time ? (I'm interested about this feature and was wondering if it has a chance to be released or not)

Thanks for the work on this library 👍

@alecthomas
Copy link
Owner

Yep, definitely.

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

Successfully merging this pull request may close these issues.

Error returned by "Any" dict validator should be of the closest alternative
4 participants