File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 9999EXTRANEOUS_WHITESPACE_REGEX = re .compile (r'[[({] | []}),;:]' )
100100WHITESPACE_AFTER_COMMA_REGEX = re .compile (r'[,;:]\s*(?: |\t)' )
101101COMPARE_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*\))' )
104104KEYWORD_REGEX = re .compile (r'(\s*)\b(?:%s)\b(\s*)' % r'|' .join (KEYWORDS ))
105105OPERATOR_REGEX = re .compile (r'(?:[^,\s])(\s*)(?:[-+*/|!<=>%&^]+)(\s*)' )
106106LAMBDA_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
954954def python_3000_has_key (logical_line ):
Original file line number Diff line number Diff line change 1414
1515if 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
1842import types
1943
You can’t perform that action at this time.
0 commit comments