Open JukkaL opened 5 years ago
I think it makes sense to give an error for this if one uses --strict-equality
, because the latter is essentially a warning about comparisons that are always false. The error message should be tweaked however (currently it mentions non-overlapping types).
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:Iterator
.Iterable
(sinceIterator
isIterable
).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 ofis
, 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.