def validate(cls, v: Any) -> Pattern: if isinstance(v, Pattern): return v elif isinstance(v, bson.regex.Regex): return re.compile(v.pattern, flags=v.flags) a = pattern_validator(v) return a
def validate(cls, v: Any) -> bson.regex.Regex: if isinstance(v, bson.regex.Regex): return v a = pattern_validator(v) return bson.regex.Regex(a.pattern)