summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorent Xicluna <florent.xicluna@gmail.com>2014-12-17 12:32:41 +0100
committerFlorent Xicluna <florent.xicluna@gmail.com>2014-12-17 12:32:41 +0100
commit42b686b9a3504ee316e6598b4ea8e7d7a52a4cf6 (patch)
tree33986dec0ed3eba52b1710b3c00501627eb99c1a
parent8452fc5e1383617b63533d9f6f586133554276f6 (diff)
parent6a2f71b19fb107983af6bb321fa6cb3b78650f4a (diff)
downloadpep8-42b686b9a3504ee316e6598b4ea8e7d7a52a4cf6.tar.gz
Merge branch fixing issues #330 and #336
-rw-r--r--CHANGES.txt2
-rwxr-xr-xpep8.py18
-rw-r--r--testsuite/E71.py15
3 files changed, 24 insertions, 11 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 168aef0..c57bfd1 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -39,6 +39,8 @@ Bug fixes:
* Missing space around keyword parameter equal not always reported, E251.
(Issue #323)
+* Fix false positive E711/E712/E713. (Issues #330 and #336)
+
1.5.7 (2014-05-29)
------------------
diff --git a/pep8.py b/pep8.py
index 2caea77..c8889b5 100755
--- a/pep8.py
+++ b/pep8.py
@@ -106,11 +106,9 @@ ERRORCODE_REGEX = re.compile(r'\b[A-Z]\d{3}\b')
DOCSTRING_REGEX = re.compile(r'u?r?["\']')
EXTRANEOUS_WHITESPACE_REGEX = re.compile(r'[[({] | []}),;:]')
WHITESPACE_AFTER_COMMA_REGEX = re.compile(r'[,;:]\s*(?: |\t)')
-COMPARE_SINGLETON_REGEX = re.compile(r'(?P<op>[=!]=)\s*'
- r'(?P<singleton>None|False|True)')
-COMPARE_SINGLETON_REVERSE_REGEX = re.compile(r'(?P<singleton>None|False|True)'
- r'\s*(?P<op>[=!]=)')
-COMPARE_NEGATIVE_REGEX = re.compile(r'\b(not)\s+[^[({ ]+\s+(in|is)\s')
+COMPARE_SINGLETON_REGEX = re.compile(r'\b(None|False|True)?\s*([=!]=)'
+ r'\s*(?(1)|(None|False|True))\b')
+COMPARE_NEGATIVE_REGEX = re.compile(r'\b(not)\s+[^][)(}{ ]+\s+(in|is)\s')
COMPARE_TYPE_REGEX = re.compile(r'(?:[=!]=|is(?:\s+not)?)\s*type(?:s.\w+Type'
r'|\s*\(\s*([^)]*[^ )])\s*\))')
KEYWORD_REGEX = re.compile(r'(\s*)\b(?:%s)\b(\s*)' % r'|'.join(KEYWORDS))
@@ -998,12 +996,10 @@ def comparison_to_singleton(logical_line, noqa):
set to some other value. The other value might have a type (such as a
container) that could be false in a boolean context!
"""
-
- match = not noqa and (COMPARE_SINGLETON_REGEX.search(logical_line) or
- COMPARE_SINGLETON_REVERSE_REGEX.search(logical_line))
+ match = not noqa and COMPARE_SINGLETON_REGEX.search(logical_line)
if match:
- singleton = match.group('singleton')
- same = (match.group('op') == '==')
+ singleton = match.group(1) or match.group(3)
+ same = (match.group(2) == '==')
msg = "'if cond is %s:'" % (('' if same else 'not ') + singleton)
if singleton in ('None',):
@@ -1013,7 +1009,7 @@ def comparison_to_singleton(logical_line, noqa):
nonzero = ((singleton == 'True' and same) or
(singleton == 'False' and not same))
msg += " or 'if %scond:'" % ('' if nonzero else 'not ')
- yield match.start(1), ("%s comparison to %s should be %s" %
+ yield match.start(2), ("%s comparison to %s should be %s" %
(code, singleton, msg))
diff --git a/testsuite/E71.py b/testsuite/E71.py
index 3f07b1a..ea870e5 100644
--- a/testsuite/E71.py
+++ b/testsuite/E71.py
@@ -46,13 +46,28 @@ if not X is Y:
#: E714
if not X.B is Y:
pass
+
+#
#: Okay
if x not in y:
pass
+
if not (X in Y or X is Z):
pass
+
if not (X in Y):
pass
+
if x is not y:
pass
+
+if TrueElement.get_element(True) == TrueElement.get_element(False):
+ pass
+
+if (True) == TrueElement or x == TrueElement:
+ pass
+
+assert (not foo) in bar
+assert {'x': not foo} in bar
+assert [42, not foo] in bar
#: