Skip to content

Commit 8ba139d

Browse files
authored
Merge pull request #992 from asottile/perf_tweak
improve performance of bare_except check
2 parents 0f079a0 + 60dc2b0 commit 8ba139d

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

pycodestyle.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ def lru_cache(maxsize=128): # noqa as it's a fake implementation.
164164
)
165165
DUNDER_REGEX = re.compile(r'^__([^\s]+)__ = ')
166166
MATCH_CASE_REGEX = re.compile(r'^\s*\b(?:match|case)(\s*)(?=.*\:)')
167+
BLANK_EXCEPT_REGEX = re.compile(r"except\s*:")
167168

168169
_checks = {'physical_line': {}, 'logical_line': {}, 'tree': {}}
169170

@@ -1488,8 +1489,7 @@ def bare_except(logical_line, noqa):
14881489
if noqa:
14891490
return
14901491

1491-
regex = re.compile(r"except\s*:")
1492-
match = regex.match(logical_line)
1492+
match = BLANK_EXCEPT_REGEX.match(logical_line)
14931493
if match:
14941494
yield match.start(), "E722 do not use bare 'except'"
14951495

0 commit comments

Comments
 (0)