next(foo) should be converted to iter(foo).next() rather than foo.next()
Bug #885203 reported by
Denis Zawada
This bug affects 1 person
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
awkwardduet |
Invalid
|
Undecided
|
Unassigned |
Bug Description
If foo already defines method called next() (In Python 3 iter.next() has been renamed to iter.__next__(), so it’s a valid name), calling foo.next() will call that method rather than iter(foo).next() as is intended. For example:
class Foo:
def next(self):
return 'bar'
def __iter__(self):
return iter(['abc'])
assert next(Foo()) == 'abc'
Will get converted to:
assert Foo().next() == 'abc'
Whereas should get converted:
assert iter(Foo()).next() == 'abc'
There are no potential regressions by changing foo.next() to iter(foo).next(), since iter() is called first by next() in Python 3 anyway.
To post a comment you must log in.
Actually this is totally wrong…