Skip to content

Commit ac223bd

Browse files
committed
allow is and is not for type compares
1 parent 9f6a181 commit ac223bd

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

pycodestyle.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@
129129
COMPARE_NEGATIVE_REGEX = re.compile(r'\b(?<!is\s)(not)\s+[^][)(}{ ]+\s+'
130130
r'(in|is)\s')
131131
COMPARE_TYPE_REGEX = re.compile(
132-
r'(?:[=!]=|is(?:\s+not)?)\s+type(?:\s*\(\s*([^)]*[^ )])\s*\))' +
133-
r'|\btype(?:\s*\(\s*([^)]*[^ )])\s*\))\s+(?:[=!]=|is(?:\s+not)?)'
132+
r'[=!]=\s+type(?:\s*\(\s*([^)]*[^ )])\s*\))'
133+
r'|\btype(?:\s*\(\s*([^)]*[^ )])\s*\))\s+[=!]='
134134
)
135135
KEYWORD_REGEX = re.compile(r'(\s*)\b(?:%s)\b(\s*)' % r'|'.join(KEYWORDS))
136136
OPERATOR_REGEX = re.compile(r'(?:[^,\s])(\s*)(?:[-+*/|!<=>%&^]+|:=)(\s*)')
@@ -1459,7 +1459,7 @@ def comparison_type(logical_line, noqa):
14591459
Do not compare types directly.
14601460
14611461
Okay: if isinstance(obj, int):
1462-
E721: if type(obj) is type(1):
1462+
E721: if type(obj) == type(1):
14631463
"""
14641464
match = COMPARE_TYPE_REGEX.search(logical_line)
14651465
if match and not noqa:

testsuite/E72.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
if res == types.IntType:
1111
pass
12-
#: E721
12+
#: Okay
1313
import types
1414

1515
if type(res) is not types.ListType:
@@ -26,9 +26,9 @@
2626
assert type(res) == type((0))
2727
#: E721
2828
assert type(res) != type((1, ))
29-
#: E721
29+
#: Okay
3030
assert type(res) is type((1, ))
31-
#: E721
31+
#: Okay
3232
assert type(res) is not type((1, ))
3333
#: E211 E721
3434
assert type(res) == type ([2, ])

0 commit comments

Comments
 (0)