Skip to content

Commit 69a3a3d

Browse files
committed
allow use # noqa to disable E721 warning
Sometimes `isinstance()` is not suitable for comparing types. For example, someone may want to make sure an object is exact instance of a type, not instance of its subclasses.
1 parent 4c5bf00 commit 69a3a3d

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

docs/intro.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ This is the current list of error and warning codes:
323323
+----------+----------------------------------------------------------------------+
324324
| E714 | test for object identity should be 'is not' |
325325
+----------+----------------------------------------------------------------------+
326-
| E721 | do not compare types, use 'isinstance()' |
326+
| E721 (^) | do not compare types, use 'isinstance()' |
327327
+----------+----------------------------------------------------------------------+
328328
| E731 | do not assign a lambda expression, use a def |
329329
+----------+----------------------------------------------------------------------+

pep8.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -974,7 +974,7 @@ def comparison_negative(logical_line):
974974
yield pos, "E714 test for object identity should be 'is not'"
975975

976976

977-
def comparison_type(logical_line):
977+
def comparison_type(logical_line, noqa):
978978
r"""Object type comparisons should always use isinstance().
979979
980980
Do not compare types directly.
@@ -990,7 +990,7 @@ def comparison_type(logical_line):
990990
Okay: if type(a1) is type(b1):
991991
"""
992992
match = COMPARE_TYPE_REGEX.search(logical_line)
993-
if match:
993+
if match and not noqa:
994994
inst = match.group(1)
995995
if inst and isidentifier(inst) and inst not in SINGLETONS:
996996
return # Allow comparison for types which are not obvious

0 commit comments

Comments
 (0)