Skip to content
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

feat: replace re module with regex #13786

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

feat: replace re module with regex #13786

wants to merge 2 commits into from

Conversation

4-9
Copy link

@4-9 4-9 commented Feb 7, 2025

This replaces all imports of the re regex module with regex. This should be backward compatible with re, so just changing the import should be enough.

Some tests fail for as yet unknown reasons, as mentioned regex should be backward compatible with re, so some tweaks to the tests might be needed.

In the UI, all works as expected. You can use the following test regex check to validate.

regex:'^[-_\p{Ll}\p{Lo}\p{N}\p{sc=Deva}\p{sc=Thai}]{1,32}$'

Fixes #13728

@nijel
Copy link
Member

nijel commented Feb 8, 2025

How about doing that in the regex check only? There is no use for this elsewhere and I'm worried about performance regressions.

@nijel
Copy link
Member

nijel commented Feb 10, 2025

Apparently, it's not 100% API compatible, so let's introduced it really in the single place where it is wanted:

AttributeError: '_regex.Pattern' object has no attribute 'decode'

@nijel nijel marked this pull request as draft February 10, 2025 14:47
@4-9 4-9 force-pushed the main branch 4 times, most recently from 9e75ee0 to f32da3e Compare February 11, 2025 15:01
@4-9 4-9 marked this pull request as ready for review February 11, 2025 15:03
@4-9
Copy link
Author

4-9 commented Feb 11, 2025

Just updating the one file file needed now.

image
image

Copy link
Member

@nijel nijel left a comment

Choose a reason for hiding this comment

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

Would you be able to add the test for the expression you wanted to use? The existing tests are in weblate/checks/tests/test_placeholders.py.

weblate/checks/placeholders.py Outdated Show resolved Hide resolved
@nijel
Copy link
Member

nijel commented Feb 12, 2025

Can you also please add types-regex==2024.11.6.20241221 to the types dependency group in pyproject.toml so that the type checker does not complain.

@nijel nijel added this to the 5.11 milestone Feb 12, 2025
@4-9 4-9 force-pushed the main branch 2 times, most recently from 4178d79 to 8c70461 Compare February 12, 2025 16:40
@4-9
Copy link
Author

4-9 commented Feb 12, 2025

I've added a test now, but not entirely sure what I'm doing. It seems to work, and would fail if re is used

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.

Support unicode categories in regex translation checks
2 participants