You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
def__iter__(self): # $ Alert # BAD: Iter does not return self
yield0
classGood1:
def__next__(self):
return0
def__iter__(self): # GOOD: iter returns self
returnself
classGood2:
def__init__(self):
self._it=iter([0,0,0])
def__next__(self):
returnnext(self._it)
def__iter__(self): # GOOD: iter and next are wrappers around a field
returnself._it.__iter__()
classGood3:
def__init__(self):
self._it=iter([0,0,0])
def__next__(self):
returnself._it.__next__()
def__iter__(self): # GOOD: iter and next are wrappers around a field
returnself._it
classGood4:
def__next__(self):
return0
def__iter__(self): # GOOD: this is an equivalent iterator to `self`.
returniter(self.__next__, None)
classFalsePositive1:
def__init__(self):
self._it=None
def__next__(self):
ifself._itisNone:
self._it=iter(self)
returnnext(self._it)
def__iter__(self): # $ Alert # SPURIOUS, GOOD: implementation of next ensures the iterator is equivalent to the one returned by iter, but this is not detected.