diff options
author | Florent Xicluna <florent.xicluna@gmail.com> | 2014-12-16 01:05:48 +0100 |
---|---|---|
committer | Florent Xicluna <florent.xicluna@gmail.com> | 2014-12-16 21:03:45 +0100 |
commit | ab63c978ac3540cd556f880d6035264deea8cb6e (patch) | |
tree | ed510c7f7b86ad538a191683b2f0ab22bcc1b497 /pep8.py | |
parent | da9f37d3d9466e1cc35579748cb8adab57b5791c (diff) | |
download | pep8-ab63c978ac3540cd556f880d6035264deea8cb6e.tar.gz |
Fix false positive E711/E712; issue #336
Diffstat (limited to 'pep8.py')
-rwxr-xr-x | pep8.py | 16 |
1 files changed, 6 insertions, 10 deletions
@@ -106,10 +106,8 @@ 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_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*\))') @@ -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)) |