Warn about comparing iterables for equality?
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Generally iter(x) == iter(x) is false, so comparing iterators and iterables for equality could often be a bug (or at least pointless). Maybe mypy should warn (at least optionally) about equality comparisons like these that have a high potential to be errors. Here is a list of things that seem suspect:
- Comparing anything ==
Iterator. - Comparing anything ==
Iterable(sinceIteratorisIterable). - Comparing
dict.values()for equality (sinced.values() != d.values()).
Mypy could recommend using the is operator instead.
I'm not sure if this is worth having. There may be some valid uses of comparing iterables using == instead of is, and it's not clear if this actually is a source of problems for programmers. A small experiment with some large codebase could help answer these questions.
I got this idea from a recent thread at python-dev.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the proposed cases: equality comparisons with Iterator or Iterable types and dict.values(). The issue suggests a small experiment on a large codebase to measure whether these comparisons are common problems; use those findings to define the warning scope and whether recommending is is appropriate.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100