Skip to content

Commit

Permalink
Merge pull request #847 from adamchainz/E225_boolean_operators
Browse files Browse the repository at this point in the history
E225 Check for space around boolean operators
  • Loading branch information
sigmavirus24 committed Mar 1, 2019
2 parents a5488e2 + 5c036dc commit d1e2986
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
7 changes: 5 additions & 2 deletions pycodestyle.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ def lru_cache(maxsize=128): # noqa as it's a fake implementation.
FUNCTION_RETURN_ANNOTATION_OP = ['->'] if sys.version_info >= (3, 5) else []
WS_NEEDED_OPERATORS = frozenset([
'**=', '*=', '/=', '//=', '+=', '-=', '!=', '<>', '<', '>',
'%=', '^=', '&=', '|=', '==', '<=', '>=', '<<=', '>>=', '='] +
'%=', '^=', '&=', '|=', '==', '<=', '>=', '<<=', '>>=', '=',
'and', 'in', 'is', 'or'] +
FUNCTION_RETURN_ANNOTATION_OP)
WHITESPACE = frozenset(' \t')
NEWLINE = frozenset([tokenize.NL, tokenize.NEWLINE])
Expand Down Expand Up @@ -824,6 +825,7 @@ def missing_whitespace_around_operator(logical_line, tokens):
E225: submitted +=1
E225: x = x /2 - 1
E225: z = x **y
E225: z = 1and 1
E226: c = (a+b) * (a-b)
E226: hypot2 = x*x + y*y
E227: c = a|b
Expand All @@ -833,6 +835,7 @@ def missing_whitespace_around_operator(logical_line, tokens):
need_space = False
prev_type = tokenize.OP
prev_text = prev_end = None
operator_types = (tokenize.OP, tokenize.NAME)
for token_type, text, start, end, line in tokens:
if token_type in SKIP_COMMENTS:
continue
Expand Down Expand Up @@ -864,7 +867,7 @@ def missing_whitespace_around_operator(logical_line, tokens):
yield (need_space[0], "%s missing whitespace "
"around %s operator" % (code, optype))
need_space = False
elif token_type == tokenize.OP and prev_end is not None:
elif token_type in operator_types and prev_end is not None:
if text == '=' and parens:
# Allow keyword args or defaults: foo(bar=None).
pass
Expand Down
8 changes: 8 additions & 0 deletions testsuite/E22.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@
i=i+ 1
#: E225 E225
i=i +1
#: E225
i = 1and 1
#: E225
i = 1or 0
#: E225
1is 1
#: E225
1in []
#: E225 E226
i=i+1
#: E225 E226
Expand Down

0 comments on commit d1e2986

Please sign in to comment.