Skip to content

Commit

Permalink
Merge pull request #992 from asottile/perf_tweak
Browse files Browse the repository at this point in the history
improve performance of bare_except check
  • Loading branch information
asottile committed May 6, 2021
2 parents 0f079a0 + 60dc2b0 commit 8ba139d
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pycodestyle.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ def lru_cache(maxsize=128): # noqa as it's a fake implementation.
)
DUNDER_REGEX = re.compile(r'^__([^\s]+)__ = ')
MATCH_CASE_REGEX = re.compile(r'^\s*\b(?:match|case)(\s*)(?=.*\:)')
BLANK_EXCEPT_REGEX = re.compile(r"except\s*:")

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

Expand Down Expand Up @@ -1488,8 +1489,7 @@ def bare_except(logical_line, noqa):
if noqa:
return

regex = re.compile(r"except\s*:")
match = regex.match(logical_line)
match = BLANK_EXCEPT_REGEX.match(logical_line)
if match:
yield match.start(), "E722 do not use bare 'except'"

Expand Down

0 comments on commit 8ba139d

Please sign in to comment.