detect compare used instead of an iterable
Bug #1614338 reported by
John Vandenberg
This bug affects 1 person
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Pyflakes |
New
|
Undecided
|
Unassigned |
Bug Description
The following will always result in
TypeError: 'bool' object is not iterable
for a in (1 == 2):
pass
It is fairly easy to detect as it is a compare in a for loop.
To post a comment you must log in.
Seems like part of a larger issue of propagating type inference from literals. int.__eq__(int) returns bool; bool.__iter__() raises TypeError. I would love to see pyflakes do this, but it would be better to do it in a generic way, rather than picking and choosing random examples.
Note that == for general objects could return anything because of __eq__ (and there are definitely some libraries that use it as syntactic sugar).