Skip to content

Commit d1e2986

Browse files
authored
Merge pull request #847 from adamchainz/E225_boolean_operators
E225 Check for space around boolean operators
2 parents a5488e2 + 5c036dc commit d1e2986

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

pycodestyle.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ def lru_cache(maxsize=128): # noqa as it's a fake implementation.
119119
FUNCTION_RETURN_ANNOTATION_OP = ['->'] if sys.version_info >= (3, 5) else []
120120
WS_NEEDED_OPERATORS = frozenset([
121121
'**=', '*=', '/=', '//=', '+=', '-=', '!=', '<>', '<', '>',
122-
'%=', '^=', '&=', '|=', '==', '<=', '>=', '<<=', '>>=', '='] +
122+
'%=', '^=', '&=', '|=', '==', '<=', '>=', '<<=', '>>=', '=',
123+
'and', 'in', 'is', 'or'] +
123124
FUNCTION_RETURN_ANNOTATION_OP)
124125
WHITESPACE = frozenset(' \t')
125126
NEWLINE = frozenset([tokenize.NL, tokenize.NEWLINE])
@@ -824,6 +825,7 @@ def missing_whitespace_around_operator(logical_line, tokens):
824825
E225: submitted +=1
825826
E225: x = x /2 - 1
826827
E225: z = x **y
828+
E225: z = 1and 1
827829
E226: c = (a+b) * (a-b)
828830
E226: hypot2 = x*x + y*y
829831
E227: c = a|b
@@ -833,6 +835,7 @@ def missing_whitespace_around_operator(logical_line, tokens):
833835
need_space = False
834836
prev_type = tokenize.OP
835837
prev_text = prev_end = None
838+
operator_types = (tokenize.OP, tokenize.NAME)
836839
for token_type, text, start, end, line in tokens:
837840
if token_type in SKIP_COMMENTS:
838841
continue
@@ -864,7 +867,7 @@ def missing_whitespace_around_operator(logical_line, tokens):
864867
yield (need_space[0], "%s missing whitespace "
865868
"around %s operator" % (code, optype))
866869
need_space = False
867-
elif token_type == tokenize.OP and prev_end is not None:
870+
elif token_type in operator_types and prev_end is not None:
868871
if text == '=' and parens:
869872
# Allow keyword args or defaults: foo(bar=None).
870873
pass

testsuite/E22.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@
7676
i=i+ 1
7777
#: E225 E225
7878
i=i +1
79+
#: E225
80+
i = 1and 1
81+
#: E225
82+
i = 1or 0
83+
#: E225
84+
1is 1
85+
#: E225
86+
1in []
7987
#: E225 E226
8088
i=i+1
8189
#: E225 E226

0 commit comments

Comments
 (0)