Skip to content

Commit 034b9f4

Browse files
committed
Add tests for the E721 check
1 parent 72269dd commit 034b9f4

2 files changed

Lines changed: 28 additions & 4 deletions

File tree

pep8.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@
9999
EXTRANEOUS_WHITESPACE_REGEX = re.compile(r'[[({] | []}),;:]')
100100
WHITESPACE_AFTER_COMMA_REGEX = re.compile(r'[,;:]\s*(?: |\t)')
101101
COMPARE_SINGLETON_REGEX = re.compile(r'([=!]=)\s*(None|False|True)')
102-
COMPARE_TYPE_REGEX = re.compile(r'([=!]=|is|is\s+not)\s*type(?:s\.(\w+)Type'
103-
r'|\(\s*(\(\s*\)|[^)]*[^ )])\s*\))')
102+
COMPARE_TYPE_REGEX = re.compile(r'(?:[=!]=|is(?:\s+not)?)\s*type(?:s.\w+Type'
103+
r'|\s*\(\s*([^)]*[^ )])\s*\))')
104104
KEYWORD_REGEX = re.compile(r'(\s*)\b(?:%s)\b(\s*)' % r'|'.join(KEYWORDS))
105105
OPERATOR_REGEX = re.compile(r'(?:[^,\s])(\s*)(?:[-+*/|!<=>%&^]+)(\s*)')
106106
LAMBDA_REGEX = re.compile(r'\blambda\b')
@@ -945,10 +945,10 @@ def comparison_type(logical_line):
945945
"""
946946
match = COMPARE_TYPE_REGEX.search(logical_line)
947947
if match:
948-
inst = match.group(3)
948+
inst = match.group(1)
949949
if inst and isidentifier(inst) and inst not in SINGLETONS:
950950
return # Allow comparison for types which are not obvious
951-
yield match.start(1), "E721 do not compare types, use 'isinstance()'"
951+
yield match.start(0), "E721 do not compare types, use 'isinstance()'"
952952

953953

954954
def python_3000_has_key(logical_line):

testsuite/E72.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,30 @@
1414

1515
if type(res) is not types.ListType:
1616
pass
17+
#: E721
18+
assert type(res) == type(False) or type(res) == type(None)
19+
#: E721
20+
assert type(res) == type([])
21+
#: E721
22+
assert type(res) == type(())
23+
#: E721
24+
assert type(res) == type((0,))
25+
#: E721
26+
assert type(res) == type((0))
27+
#: E721
28+
assert type(res) != type((1, ))
29+
#: E721
30+
assert type(res) is type((1, ))
31+
#: E721
32+
assert type(res) is not type((1, ))
33+
#: E211 E721
34+
assert type(res) == type ([2, ])
35+
#: E201 E202 E721
36+
assert type(res) == type( ( ) )
37+
#: E201 E202 E721
38+
assert type(res) == type( (0, ) )
39+
#:
40+
1741
#: Okay
1842
import types
1943

0 commit comments

Comments
 (0)