Open samuelcolvin opened 1 year ago
How would validators behave in this case? E.g.
class Model(BaseModel):
prop_a: int
class Config:
extra_pattern = {r'^prop_': str}
@validator(r'^prop_')
def validate_props(cls, v) -> str:
return v.upper()
I don't care about the python interface yet, let's work out how it should work in rust first.
I guess this should be added to TypedDictValidator
.
I think the best solution would be to convert
Into
patterns: Vec<PatternField>,
Where PatternField
is
enum Pattern {
Regex(Regex),
Function(PyObject),
All,
}
struct PatternField {
descriminator: Pattern,
validator: CombinedValidator,
}
Then
Becomes:
for pattern in self.patterns {
if pattern.matches(value) {
...
}
}
In python I guess patternProperties
will have to be defined via config since we can't use attributes and annotations as we don't know what the key will be.
@samuelcolvin, is this still a relevant issue?
See https://github.com/pydantic/pydantic/discussions/3303.
We should allow the descriminator to be a regex or function.