summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorent Xicluna <florent.xicluna@gmail.com>2013-02-24 14:49:47 +0100
committerFlorent Xicluna <florent.xicluna@gmail.com>2013-02-24 14:49:47 +0100
commit034b9f4fb082f72e1087a8a27dd0dd61486d1888 (patch)
treea9c84e70f0610416ba9cf98913aced064c09da73
parent72269ddfebfbe7075079b224df30c7c989aa7281 (diff)
downloadpep8-034b9f4fb082f72e1087a8a27dd0dd61486d1888.tar.gz
Add tests for the E721 check
-rwxr-xr-xpep8.py8
-rw-r--r--testsuite/E72.py24
2 files changed, 28 insertions, 4 deletions
diff --git a/pep8.py b/pep8.py
index 6799faf..5578261 100755
--- a/pep8.py
+++ b/pep8.py
@@ -99,8 +99,8 @@ 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'([=!]=)\s*(None|False|True)')
-COMPARE_TYPE_REGEX = re.compile(r'([=!]=|is|is\s+not)\s*type(?:s\.(\w+)Type'
- r'|\(\s*(\(\s*\)|[^)]*[^ )])\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))
OPERATOR_REGEX = re.compile(r'(?:[^,\s])(\s*)(?:[-+*/|!<=>%&^]+)(\s*)')
LAMBDA_REGEX = re.compile(r'\blambda\b')
@@ -945,10 +945,10 @@ def comparison_type(logical_line):
"""
match = COMPARE_TYPE_REGEX.search(logical_line)
if match:
- inst = match.group(3)
+ inst = match.group(1)
if inst and isidentifier(inst) and inst not in SINGLETONS:
return # Allow comparison for types which are not obvious
- yield match.start(1), "E721 do not compare types, use 'isinstance()'"
+ yield match.start(0), "E721 do not compare types, use 'isinstance()'"
def python_3000_has_key(logical_line):
diff --git a/testsuite/E72.py b/testsuite/E72.py
index da041af..514995a 100644
--- a/testsuite/E72.py
+++ b/testsuite/E72.py
@@ -14,6 +14,30 @@ import types
if type(res) is not types.ListType:
pass
+#: E721
+assert type(res) == type(False) or type(res) == type(None)
+#: E721
+assert type(res) == type([])
+#: E721
+assert type(res) == type(())
+#: E721
+assert type(res) == type((0,))
+#: E721
+assert type(res) == type((0))
+#: E721
+assert type(res) != type((1, ))
+#: E721
+assert type(res) is type((1, ))
+#: E721
+assert type(res) is not type((1, ))
+#: E211 E721
+assert type(res) == type ([2, ])
+#: E201 E202 E721
+assert type(res) == type( ( ) )
+#: E201 E202 E721
+assert type(res) == type( (0, ) )
+#:
+
#: Okay
import types