Skip to content

Commit ab63c97

Browse files
committed
Fix false positive E711/E712; issue #336
1 parent da9f37d commit ab63c97

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ Bug fixes:
3636

3737
* Don't crash if os.path.expanduser() throws an ImportError. (Issue #297)
3838

39+
* Fix false positive E711/E712. (Issue #336)
40+
3941

4042
1.5.7 (2014-05-29)
4143
------------------

pep8.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,8 @@
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>[=!]=)')
109+
COMPARE_SINGLETON_REGEX = re.compile(r'\b(None|False|True)?\s*([=!]=)'
110+
r'\s*(?(1)|(None|False|True))\b')
113111
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*\))')
@@ -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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,9 @@
5555
pass
5656
if x is not y:
5757
pass
58+
59+
if TrueElement.get_element(True) == TrueElement.get_element(False):
60+
pass
61+
if (True) == TrueElement or x == TrueElement:
62+
pass
5863
#:

0 commit comments

Comments
 (0)