Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
Changelog
=========

Unreleased
----------

Changes:

* E721: also report reversed comparisons like ``int == type(obj)``.
Issue #1187.

2.14.0 (2025-06-20)
-------------------

Expand Down
6 changes: 3 additions & 3 deletions pycodestyle.py
Original file line number Diff line number Diff line change
Expand Up @@ -1498,12 +1498,12 @@ def comparison_type(logical_line, noqa):
Okay: if isinstance(obj, int):
Okay: if type(obj) is int:
E721: if type(obj) == type(1):
E721: if type(obj) == int:
E721: if int == type(obj):
"""
match = COMPARE_TYPE_REGEX.search(logical_line)
if match and not noqa:
inst = match.group(1)
if inst and inst.isidentifier() and inst not in SINGLETONS:
return # Allow comparison for types which are not obvious
# Flag both type(x) == T and T == type(x) (and !=).
yield (
match.start(),
"E721 do not compare types, for exact checks use `is` / `is not`, "
Expand Down
9 changes: 9 additions & 0 deletions testing/data/E72.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,12 @@ def func_histype(a, b, c):

if compute_type(foo) == 5:
pass
#: E721
if type(obj) == int:
pass
#: E721
if int == type(obj):
pass
#: E721
if int != type(obj):
pass
Loading