Skip to content

Commit

Permalink
Add types, add test
Browse files Browse the repository at this point in the history
  • Loading branch information
4-9 committed Feb 12, 2025
1 parent 61ce453 commit 4243dea
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 5 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ types = [
"types-openpyxl==3.1.5.20241225",
"types-Pillow==10.2.0.20240822",
"types-python-dateutil==2.9.0.20241206",
"types-regex==2024.11.6.20241221",
"types-requests==2.32.0.20241016"
]

Expand Down
13 changes: 13 additions & 0 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions weblate/checks/placeholders.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from typing import TYPE_CHECKING, Any, Literal

import regex as re
import regex
from django.utils.functional import SimpleLazyObject
from django.utils.html import escape, format_html, format_html_join
from django.utils.safestring import mark_safe
Expand All @@ -21,7 +21,7 @@

def parse_regex(val):
if isinstance(val, str):
return re.compile(val)
return regex.compile(val)
return val


Expand All @@ -36,12 +36,12 @@ def param_type(self):
return multi_value_flag(lambda x: x)

def get_value(self, unit: Unit):
return re.compile(
return regex.compile(
"|".join(
re.escape(param) if isinstance(param, str) else param.pattern
regex.escape(param) if isinstance(param, str) else param.pattern
for param in super().get_value(unit)
),
re.IGNORECASE if "case-insensitive" in unit.all_flags else 0,
regex.IGNORECASE if "case-insensitive" in unit.all_flags else 0,
)

@staticmethod
Expand Down
17 changes: 17 additions & 0 deletions weblate/checks/tests/test_placeholders.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,20 @@ def test_check_highlight_groups(self) -> None:
(36, 43, "{foo32}"),
],
)

def test_unicode_regex(self) -> None:
unit = MockUnit(
None,
r'regex:"((?:@:\(|\{)[-_\p{Lo}\p{Ll}\p{N}]+(?:\)|\}))"',
self.default_lang,
"@:(你好世界一۲༣) | @:(Hello-World123) | @:(你好世界一۲༣!) | @:(-你好世界一۲༣_) "
"| {hello-world123}",
)
self.assertEqual(
list(self.check.check_highlight(unit.source, unit)),

Check failure on line 248 in weblate/checks/tests/test_placeholders.py

View workflow job for this annotation

GitHub Actions / mypy

Argument 2 to "check_highlight" of "RegexCheck" has incompatible type "MockUnit"; expected "Unit"
[
(0, 11, "@:(你好世界一۲༣)"),
(50, 63, "@:(-你好世界一۲༣_)"),
(66, 82, "{hello-world123}"),
],
)

0 comments on commit 4243dea

Please sign in to comment.