Skip to content

Commit 42b686b

Browse files
committed
Merge branch fixing issues #330 and #336
2 parents 8452fc5 + 6a2f71b commit 42b686b

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ Bug fixes:
3939
* Missing space around keyword parameter equal not always reported, E251.
4040
(Issue #323)
4141

42+
* Fix false positive E711/E712/E713. (Issues #330 and #336)
43+
4244

4345
1.5.7 (2014-05-29)
4446
------------------

pep8.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,9 @@
106106
DOCSTRING_REGEX = re.compile(r'u?r?["\']')
107107
EXTRANEOUS_WHITESPACE_REGEX = re.compile(r'[[({] | []}),;:]')
108108
WHITESPACE_AFTER_COMMA_REGEX = re.compile(r'[,;:]\s*(?: |\t)')
109-
COMPARE_SINGLETON_REGEX = re.compile(r'(?P<op>[=!]=)\s*'
110-
r'(?P<singleton>None|False|True)')
111-
COMPARE_SINGLETON_REVERSE_REGEX = re.compile(r'(?P<singleton>None|False|True)'
112-
r'\s*(?P<op>[=!]=)')
113-
COMPARE_NEGATIVE_REGEX = re.compile(r'\b(not)\s+[^[({ ]+\s+(in|is)\s')
109+
COMPARE_SINGLETON_REGEX = re.compile(r'\b(None|False|True)?\s*([=!]=)'
110+
r'\s*(?(1)|(None|False|True))\b')
111+
COMPARE_NEGATIVE_REGEX = re.compile(r'\b(not)\s+[^][)(}{ ]+\s+(in|is)\s')
114112
COMPARE_TYPE_REGEX = re.compile(r'(?:[=!]=|is(?:\s+not)?)\s*type(?:s.\w+Type'
115113
r'|\s*\(\s*([^)]*[^ )])\s*\))')
116114
KEYWORD_REGEX = re.compile(r'(\s*)\b(?:%s)\b(\s*)' % r'|'.join(KEYWORDS))
@@ -998,12 +996,10 @@ def comparison_to_singleton(logical_line, noqa):
998996
set to some other value. The other value might have a type (such as a
999997
container) that could be false in a boolean context!
1000998
"""
1001-
1002-
match = not noqa and (COMPARE_SINGLETON_REGEX.search(logical_line) or
1003-
COMPARE_SINGLETON_REVERSE_REGEX.search(logical_line))
999+
match = not noqa and COMPARE_SINGLETON_REGEX.search(logical_line)
10041000
if match:
1005-
singleton = match.group('singleton')
1006-
same = (match.group('op') == '==')
1001+
singleton = match.group(1) or match.group(3)
1002+
same = (match.group(2) == '==')
10071003

10081004
msg = "'if cond is %s:'" % (('' if same else 'not ') + singleton)
10091005
if singleton in ('None',):
@@ -1013,7 +1009,7 @@ def comparison_to_singleton(logical_line, noqa):
10131009
nonzero = ((singleton == 'True' and same) or
10141010
(singleton == 'False' and not same))
10151011
msg += " or 'if %scond:'" % ('' if nonzero else 'not ')
1016-
yield match.start(1), ("%s comparison to %s should be %s" %
1012+
yield match.start(2), ("%s comparison to %s should be %s" %
10171013
(code, singleton, msg))
10181014

10191015

testsuite/E71.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,28 @@
4646
#: E714
4747
if not X.B is Y:
4848
pass
49+
50+
#
4951
#: Okay
5052
if x not in y:
5153
pass
54+
5255
if not (X in Y or X is Z):
5356
pass
57+
5458
if not (X in Y):
5559
pass
60+
5661
if x is not y:
5762
pass
63+
64+
if TrueElement.get_element(True) == TrueElement.get_element(False):
65+
pass
66+
67+
if (True) == TrueElement or x == TrueElement:
68+
pass
69+
70+
assert (not foo) in bar
71+
assert {'x': not foo} in bar
72+
assert [42, not foo] in bar
5873
#:

0 commit comments

Comments
 (0)