From 15bf53ac940aa46b280b2c16761f1dd61642c1ed Mon Sep 17 00:00:00 2001 From: T0209181 Date: Thu, 14 Jul 2022 16:04:30 -0400 Subject: [PATCH 1/2] Updates to E203 --- pycodestyle.py | 15 +++++++++++++-- testsuite/E20.py | 4 ++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/pycodestyle.py b/pycodestyle.py index f866dd4a..ff5042b2 100755 --- a/pycodestyle.py +++ b/pycodestyle.py @@ -128,7 +128,13 @@ RERAISE_COMMA_REGEX = re.compile(r'raise\s+\w+\s*,.*,\s*\w+\s*$') ERRORCODE_REGEX = re.compile(r'\b[A-Z]\d{3}\b') DOCSTRING_REGEX = re.compile(r'u?r?["\']') -EXTRANEOUS_WHITESPACE_REGEX = re.compile(r'[\[({][ \t]|[ \t][\]}),;:](?!=)') +EXTRANEOUS_WHITESPACE_REGEX = re.compile( + r'(' + r'[\[({][ \t]|' + r'(?P\[[^]]*)[^]]]?|' + r'[ \t][]}),;:](?!=)' + r')' +) WHITESPACE_AFTER_COMMA_REGEX = re.compile(r'[,;:]\s*(?: |\t)') COMPARE_SINGLETON_REGEX = re.compile(r'(\bNone|\bFalse|\bTrue)?\s*([=!]=)' r'\s*(?(1)|(None|False|True))\b') @@ -445,13 +451,18 @@ def extraneous_whitespace(logical_line): line = logical_line for match in EXTRANEOUS_WHITESPACE_REGEX.finditer(line): text = match.group() - char = text.strip() + char = text.strip()[-1] found = match.start() if text[-1].isspace(): # assert char in '([{' yield found + 1, "E201 whitespace after '%s'" % char elif line[found - 1] != ',': code = ('E202' if char in '}])' else 'E203') # if char in ',;:' + if "in_brackets" in match.groupdict(): # Not first case of regex + if not re.match(r"[ \t]", text[-2]): # No space + continue + if len(text) > 2 and text[-3] == ",": # comma space + continue yield found, f"{code} whitespace before '{char}'" diff --git a/testsuite/E20.py b/testsuite/E20.py index 20c6dfd8..73e238ea 100644 --- a/testsuite/E20.py +++ b/testsuite/E20.py @@ -19,13 +19,13 @@ spam(ham[1], {eggs: 2} ) #: E202:1:22 spam(ham[1], {eggs: 2 }) -#: E202:1:11 +#: E202:1:9 spam(ham[1 ], {eggs: 2}) #: E202:1:23 spam(ham[1], {eggs: 2} ) #: E202:1:22 spam(ham[1], {eggs: 2 }) -#: E202:1:11 +#: E202:1:9 spam(ham[1 ], {eggs: 2}) #: Okay spam(ham[1], {eggs: 2}) From 97d43d1d9fbce67c5eb74485fd25c76b39c26c39 Mon Sep 17 00:00:00 2001 From: T0209181 Date: Thu, 14 Jul 2022 16:14:20 -0400 Subject: [PATCH 2/2] Add new check for E203 --- testsuite/E20.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/testsuite/E20.py b/testsuite/E20.py index 73e238ea..145d4613 100644 --- a/testsuite/E20.py +++ b/testsuite/E20.py @@ -75,4 +75,9 @@ x, y = y, x a[b1, :] == a[b1, ...] b = a[:, b1] -#: +#: Okay +if x == 4: + print x, y + x, y = y, x +a[1 : 2] == a[b1, ...] +b = a[:, b1]