File tree Expand file tree Collapse file tree 1 file changed +7
-2
lines changed Expand file tree Collapse file tree 1 file changed +7
-2
lines changed Original file line number Diff line number Diff line change @@ -1456,19 +1456,24 @@ def comparison_negative(logical_line):
1456
1456
1457
1457
@register_check
1458
1458
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()` .
1460
1460
1461
1461
Do not compare types directly.
1462
1462
1463
1463
Okay: if isinstance(obj, int):
1464
+ Okay: if type(obj) is int:
1464
1465
E721: if type(obj) == type(1):
1465
1466
"""
1466
1467
match = COMPARE_TYPE_REGEX .search (logical_line )
1467
1468
if match and not noqa :
1468
1469
inst = match .group (1 )
1469
1470
if inst and inst .isidentifier () and inst not in SINGLETONS :
1470
1471
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
+ )
1472
1477
1473
1478
1474
1479
@register_check
You can’t perform that action at this time.
0 commit comments