Skip to content

Conversation

@smaye81
Copy link
Contributor

@smaye81 smaye81 commented Jun 18, 2025

This adds the ability to the Config object for specifying an optional custom matcher. If provided, it will be invoked instead of protovalidate-python's matches implementation.

"""An implementation of string.format() in CEL."""

def __init__(self, locale: str):
self.locale = locale
Copy link
Contributor Author

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.

@smaye81 smaye81 requested review from Alfus and stefanvanburen June 18, 2025 17:18
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]]):
Copy link
Member

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?

Copy link
Contributor Author

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.

function via the Config.
Raises:
celpy.CELEvalError: If pattern contains invalid re2 syntax.
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, done.

@smaye81 smaye81 merged commit 55914af into main Jun 18, 2025
12 checks passed
@smaye81 smaye81 deleted the sayers/byo_re2 branch June 18, 2025 18:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants