Skip to content

E721: report reversed type comparisons#1319

Closed
l46983284-cpu wants to merge 1 commit into
PyCQA:mainfrom
l46983284-cpu:fix-1187-e721-reversed-type-compare
Closed

E721: report reversed type comparisons#1319
l46983284-cpu wants to merge 1 commit into
PyCQA:mainfrom
l46983284-cpu:fix-1187-e721-reversed-type-compare

Conversation

@l46983284-cpu

Copy link
Copy Markdown

Summary

E721 already caught type(obj) == int but not the reversed form int == type(obj), because comparison_type returned early when the first capture group (type on the right of ==/!=) was a plain identifier.

This drops that early return so both comparison orders are reported. Allowed exact checks remain type(x) is T / is not, and instance checks stay isinstance().

Fixes #1187

Test plan

  • Added reversed cases to testing/data/E72.py
  • pytest tests/ testing/ -q → 767 passed, 11 skipped

E721 only flagged `type(x) == T` and missed `T == type(x)` because the
allow-path inspected only the first regex capture group. Always report
when COMPARE_TYPE_REGEX matches so both orders are covered.

Fixes PyCQA#1187

Signed-off-by: Alex Chen <l46983284@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

E721: pycodestyle v2.11.0 does not raise the error to int == type(obj)

2 participants