Skip to content

Commit 8b5c964

Browse files
authored
Merge pull request #1041 from asfaltboy/issue-830-e721-types-regex-incorrect
fix E721 types regex
2 parents 9777ac5 + 5df259b commit 8b5c964

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

pycodestyle.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,10 @@ def lru_cache(maxsize=128): # noqa as it's a fake implementation.
144144
r'\s*(?(1)|(None|False|True))\b')
145145
COMPARE_NEGATIVE_REGEX = re.compile(r'\b(?<!is\s)(not)\s+[^][)(}{ ]+\s+'
146146
r'(in|is)\s')
147-
COMPARE_TYPE_REGEX = re.compile(r'(?:[=!]=|is(?:\s+not)?)\s+type(?:s.\w+Type'
148-
r'|\s*\(\s*([^)]*[^ )])\s*\))')
147+
COMPARE_TYPE_REGEX = re.compile(
148+
r'(?:[=!]=|is(?:\s+not)?)\s+type(?:\s*\(\s*([^)]*[^ )])\s*\))' +
149+
r'|type(?:\s*\(\s*([^)]*[^ )])\s*\))\s+(?:[=!]=|is(?:\s+not)?)'
150+
)
149151
KEYWORD_REGEX = re.compile(r'(\s*)\b(?:%s)\b(\s*)' % r'|'.join(KEYWORDS))
150152
OPERATOR_REGEX = re.compile(r'(?:[^,\s])(\s*)(?:[-+*/|!<=>%&^]+|:=)(\s*)')
151153
LAMBDA_REGEX = re.compile(r'\blambda\b')
@@ -1463,7 +1465,6 @@ def comparison_type(logical_line, noqa):
14631465
common base class, basestring, so you can do:
14641466
14651467
Okay: if isinstance(obj, basestring):
1466-
Okay: if type(a1) is type(b1):
14671468
"""
14681469
match = COMPARE_TYPE_REGEX.search(logical_line)
14691470
if match and not noqa:

testsuite/E72.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#: E721
55
if type(res) != type(""):
66
pass
7-
#: E721
7+
#: Okay
88
import types
99

1010
if res == types.IntType:
@@ -47,8 +47,6 @@
4747
pass
4848
if isinstance(res, types.MethodType):
4949
pass
50-
if type(a) != type(b) or type(a) == type(ccc):
51-
pass
5250
#: Okay
5351
def func_histype(a, b, c):
5452
pass
@@ -80,3 +78,8 @@ def func_histype(a, b, c):
8078
pass
8179
except Exception:
8280
pass
81+
#: Okay
82+
from . import custom_types as types
83+
84+
red = types.ColorTypeRED
85+
red is types.ColorType.RED

0 commit comments

Comments
 (0)