Skip to content

Conversation

@smaye81
Copy link
Contributor

@smaye81 smaye81 commented Jun 12, 2025

This implements an override of the matches function in celpy, which allows us to perform quasi-re2 operations. Since google-re2 does not yet support Python 3.13, we cannot use it in protovalidate-python.

So, as a good compromise until then, we are simulating re2 behavior much like protovalidate-es does by failing on syntax not allowed in re2.

Note that protovalidate-es also parses regex flags at the beginning of regex patterns and applies them at the end. This is because ECMAScript regex does not support flags at the beginning. However, Python's re package does support this. So really all this does for now is to simply fail on invalid re2 syntax.

A future PR will add the ability for users to specify their own re2 engine via a config if they would like to override this behavior (which would not be a breaking change).

@smaye81 smaye81 marked this pull request as ready for review June 16, 2025 17:53
try:
m = re.search(pattern, text)
except re.error as ex:
return celpy.CELEvalError("match error", ex.__class__, ex.args)
Copy link
Member

Choose a reason for hiding this comment

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

does this match handling in celpy? or should we pull it out in an f-string + msg like the others?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried to match what celpy was doing here yeah: See code here.

Copy link
Member

Choose a reason for hiding this comment

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

ah, gotcha, my searching was not finding that code. works for me!

@smaye81 smaye81 merged commit 4dd9232 into main Jun 17, 2025
13 checks passed
@smaye81 smaye81 deleted the sayers/re2_workaround branch June 17, 2025 04:19
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.

5 participants