next(foo) should be converted to iter(foo).next() rather than foo.next()

Bug #885203 reported by Denis Zawada
6
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.

Revision history for this message
Denis Zawada (ohdeno) wrote :

Actually this is totally wrong…

Changed in awkwardduet:
status: Confirmed → Invalid
milestone: 1.1a2 → none
importance: Low → Wishlist
importance: Wishlist → Undecided
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.