_validate_value or _validate?

Parameter objects have both a _validate_value and a _validate method. If I’m implementing a new Parameter subclass, which one should I implement, and how should I think about the difference between the two of them?

The docs give an example of implementing your own _validate_value, whereas the documentation for _validate says that “Subclasses can extend this method to include additional validation logic.”

With my current understanding, _validate is the broader choice, since it looks like it often is the one to call _validate_value.

1 Like

The value is the most common thing to validate, so _validate_value is what’s typically implemented. You can look at param.String to see an example of validating things other than the value:

    def _validate(self, val):
        self._validate_value(val, self.allow_None)
        self._validate_regex(val, self.regex)

So _validate is the broader choice, as it’s more powerful, but you should normally focus on the least broad option that does the job. So if what’s being validated in your class is the value, then provide _validate_value, and if you’re going to do some more complex validation checking the various other possible Parameter slots, that can be done in _validate (which should still call _validate_value to do the part of the validation involving the value).

Thanks for that explanation, that helps!