Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates to E203 #1082

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions pycodestyle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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<in_brackets>\[[^]]*)[^]]]?|'
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')
Expand Down Expand Up @@ -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}'"


Expand Down
11 changes: 8 additions & 3 deletions testsuite/E20.py
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down Expand Up @@ -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]