PyCQA / PyCQA/pycodestyle

E721: suggest reasonable alternative

Open
#882 12 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
5.2k
Forks
754
PR merge metrics
No merged PRs in 30d

Description

E721 is there to prevent type(3) == int in favour of isinstance(3, int). Thats fine.

But it also raises an error for code like type(a) == type(b). This is good code though and I don't know of a better way to test if two values have the same type. Of course you can go for isinstance(a, type(b)), but that is longer and less readable.

I suggest either changing E721 to not match lines like the above or to suggest a reasonable alternative to the line above.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the E721 checker entry point in pycodestyle's single Python file and inspect the existing tests for this rule. Reproduce both type(a) == type(b) and type(3) == int, then define and verify the intended diagnostic or alternative behavior with regression coverage.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.