-
Notifications
You must be signed in to change notification settings - Fork 9
Add ability to specify custom regex matcher #325
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
Conversation
| """An implementation of string.format() in CEL.""" | ||
|
|
||
| def __init__(self, locale: str): | ||
| self.locale = locale |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
locale was not used anywhere. We can add it back when/if it's needed.
protovalidate/internal/extra_func.py
Outdated
| def make_extra_funcs(locale: str) -> dict[str, celpy.CELFunction]: | ||
| # For now, ignoring the type. | ||
| string_fmt = string_format.StringFormat(locale) # type: ignore | ||
| def get_matches_func(matcher: typing.Optional[typing.Callable[[str, str], bool]]): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
honestly haven't kept up with type hints in Python but should we be using collections.abc.Callable instead, since typing.Callable seems to be a deprecated alias as of 3.9?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh nice. Thanks. Wonder why the linter didn't catch that. 🤷 . Fixed.
protovalidate/internal/matches.py
Outdated
| function via the Config. | ||
| Raises: | ||
| celpy.CELEvalError: If pattern contains invalid re2 syntax. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're also raising this on re.error on the second re.search, do we want to document when that will go wrong?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, done.
This adds the ability to the
Configobject for specifying an optional custom matcher. If provided, it will be invoked instead of protovalidate-python'smatchesimplementation.