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

Is it possible to specify a Hook based on absent key? #274

Open
redruin1 opened this issue Jan 7, 2022 · 0 comments
Open

Is it possible to specify a Hook based on absent key? #274

redruin1 opened this issue Jan 7, 2022 · 0 comments

Comments

@redruin1
Copy link

redruin1 commented Jan 7, 2022

Suppose I have some data with a key that is desired but not necessary:

some_data = {
    "required_key_1": [ ... ],
    "required_key_2": [ ... ],
    "optional_data": "expected and desired, but not absolutely needed"
}

I'd like to have it setup where if optional_data is absent, it calls a logging function outputting a warning (i.e. "Expected 'optional_data'; are you sure your data is valid?"). Of course, optional_data is not required and can be inferred if needed using Optional.

I'd like to setup a Hook to output this warning if the key is not present in the data, but Hook only seems to have a callback for if the key is detected. Is there any way to get this functionality? Something like:

schema = Schema({
    "required_key_1": list,
    "required_key_2": list,
    Expected("optional_data"): str # or Expected(Optional("optional_data"))
})
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