Skip to content

Commit 2f9a0b5

Browse files
committed
E721: have the message better match the check
1 parent b4c660a commit 2f9a0b5

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

pycodestyle.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1456,19 +1456,24 @@ def comparison_negative(logical_line):
14561456

14571457
@register_check
14581458
def comparison_type(logical_line, noqa):
1459-
r"""Object type comparisons should always use isinstance().
1459+
r"""Object type comparisons should `is` / `is not` / `isinstance()`.
14601460
14611461
Do not compare types directly.
14621462
14631463
Okay: if isinstance(obj, int):
1464+
Okay: if type(obj) is int:
14641465
E721: if type(obj) == type(1):
14651466
"""
14661467
match = COMPARE_TYPE_REGEX.search(logical_line)
14671468
if match and not noqa:
14681469
inst = match.group(1)
14691470
if inst and inst.isidentifier() and inst not in SINGLETONS:
14701471
return # Allow comparison for types which are not obvious
1471-
yield match.start(), "E721 do not compare types, use 'isinstance()'"
1472+
yield (
1473+
match.start(),
1474+
"E721 do not compare types, for exact checks use `is` / `is not`, "
1475+
"for instance checks use `isinstance()`",
1476+
)
14721477

14731478

14741479
@register_check

0 commit comments

Comments
 (0)