Skip to content

Commit 0cd03ad

Browse files
committed
Precompile regex patterns
1 parent dafd19d commit 0cd03ad

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

flake8_strftime/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@
4949
STRFTIME001 = "STRFTIME001 Linux-specific strftime code used."
5050
STRFTIME002 = "STRFTIME002 Windows-specific strftime code used."
5151

52+
_linux_re = re.compile(r"%-[dmHIMSj]")
53+
_win_re = re.compile(r"%#[dmHIMSj]")
54+
5255

5356
class Visitor(flake8_helper.Visitor): # noqa: D101
5457

@@ -90,7 +93,7 @@ def _check_linux(self, node: Union[ast.Str, ast.Constant]):
9093
:param node: The node being visited
9194
"""
9295

93-
for match in re.finditer(r"%-[dmHIMSj]", node.s):
96+
for match in _linux_re.finditer(node.s):
9497
self.errors.append((
9598
node.lineno,
9699
node.col_offset + match.span()[0],
@@ -104,7 +107,7 @@ def _check_windows(self, node: Union[ast.Str, ast.Constant]):
104107
:param node: The node being visited
105108
"""
106109

107-
for match in re.finditer(r"%#[dmHIMSj]", node.s):
110+
for match in _win_re.finditer(node.s):
108111
self.errors.append((
109112
node.lineno,
110113
node.col_offset + match.span()[0],

0 commit comments

Comments
 (0)