Skip to content

Commit 43c5386

Browse files
committed
Avoid re-compiling regular expression
While the re module caches some of the latest compilations, it's better form to not rely on it doing so. Signed-off-by: Rodrigo Tobar <rtobar@icrar.org>
1 parent 740ee3d commit 43c5386

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

babel/messages/pofile.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
from typing_extensions import Literal
2727

2828

29+
_ESCAPED_CHARACTER_PATTERN = re.compile(r'\\([\\trn"])')
30+
2931
def unescape(string: str) -> str:
3032
r"""Reverse `escape` the given string.
3133
@@ -46,7 +48,7 @@ def replace_escapes(match):
4648
return '\r'
4749
# m is \ or "
4850
return m
49-
return re.compile(r'\\([\\trn"])').sub(replace_escapes, string[1:-1])
51+
return _ESCAPED_CHARACTER_PATTERN.sub(replace_escapes, string[1:-1])
5052

5153

5254
def denormalize(string: str) -> str:

0 commit comments

Comments
 (0)