summaryrefslogtreecommitdiff
path: root/pycodestyle.py
diff options
context:
space:
mode:
authorAnthony Sottile <asottile@umich.edu>2021-05-04 16:46:40 -0700
committerAnthony Sottile <asottile@umich.edu>2021-05-04 16:49:00 -0700
commit60dc2b0d7b75c46a41612d2d0f6a9430b4dcdc40 (patch)
treecc71df1f6c03bc4953ab08ca473c3fc2f26f1c55 /pycodestyle.py
parent0f079a061590217515421fc337df8dbf3563fed5 (diff)
downloadpep8-60dc2b0d7b75c46a41612d2d0f6a9430b4dcdc40.tar.gz
improve performance of bare_except check
- despite `re.compile(...)` being cached, this still amounts to 60% of the overhead of the `bare_except` check - overall, this improved pycodestyle performance by about .25% (.0025)
Diffstat (limited to 'pycodestyle.py')
-rwxr-xr-xpycodestyle.py4
1 files changed, 2 insertions, 2 deletions
diff --git a/pycodestyle.py b/pycodestyle.py
index 7f00739..52bcc09 100755
--- a/pycodestyle.py
+++ b/pycodestyle.py
@@ -164,6 +164,7 @@ STARTSWITH_INDENT_STATEMENT_REGEX = re.compile(
)
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': {}}
@@ -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'"