This rule wants
needle = None
for smth in it:
if smth is worthy:
needle = smth
break
else:
raise LookupError
But inside of the lookup-style functions it's reasonable to just return early instead of maintaining an extra var:
def func(it):
for smth in it:
if smth is worthy:
return smth
else:
raise LookupError
This case does not trigger raise when return interrupts the loop, just like break. I think it should not be reported.
In case of using return, you can omit else:
def func(it):
for smth in it:
if smth is worthy:
return smth
raise LookupError
I hardly can imagine a case when else for for is needed without break. According to the documentation, break is the only flow control statement that "terminates the loop without executing the else clause鈥檚 suite". For every other case, else can be just inlined.
If you don't mind, I close the issue.