-
Notifications
You must be signed in to change notification settings - Fork 2
Closed
Labels
good first issueGood for newcomersGood for newcomersnew validatorImplementation of a new validator classImplementation of a new validator class
Milestone
Description
Implement a DiscardValidator that accepts any kind of input, but discards it and returns a (predefined) value instead.
There are no validation errors for this validator, the input is just completely ignored. (For a validator that rejects any kind of input, there already is the RejectValidator.)
The implementation could look somewhat like this (copied from a project):
class DiscardValidator(Validator):
"""
Meta validator that simply discards any input and always returns the same predefined value.
Set the `output_value` parameter to any value to specify the value returned by the validator. If not set, the value
defaults to `None`.
"""
# Value that is returned by the validator
output_value: Any
def __init__(self, *, output_value: Any = None):
self.return_value = output_value
def validate(self, input_data: Any, **kwargs) -> Any:
# Ignore input completely and just return the predefined output value
return self.output_valueMetadata
Metadata
Assignees
Labels
good first issueGood for newcomersGood for newcomersnew validatorImplementation of a new validator classImplementation of a new validator class