Re: [code-quality] Spurious useless-else-on-loop warning

2013-09-17 Thread Ned Batchelder
On 9/17/13 2:56 PM, Skip Montanaro wrote: I have a function which uses for ... else, with an early return. Here's a cut down version of it: """...""" def func(c, dt, ct): for cl, op in zip(c.events[0::2], c.events[1::2]): delta = cl.event_datetime - dt if delta > ct:

[code-quality] Spurious useless-else-on-loop warning

2013-09-17 Thread Skip Montanaro
I have a function which uses for ... else, with an early return. Here's a cut down version of it: """...""" def func(c, dt, ct): for cl, op in zip(c.events[0::2], c.events[1::2]): delta = cl.event_datetime - dt if delta > ct: return dt + ct else:

Re: [code-quality] Spurious useless-else-on-loop warning

2013-09-17 Thread Ned Batchelder
On 9/17/13 7:56 PM, Skip Montanaro wrote: > But this "else" is useless, isn't it? Just put the "return dt" statement after the for statement, no else needed. In this particular case, yes, but that's not the point of the post. Pylint doesn't check to see what's in the else clause, only whet

[code-quality] Fwd: Spurious useless-else-on-loop warning

2013-09-17 Thread Skip Montanaro
Ned, I still think you're missing the point of my original post. A return is as good as a break when considering early exit from a loop. The pylint code only checks for the presence of a break statement, but the test cases clearly show a case with a return statement. The test functions even includ

[code-quality] Fwd: Spurious useless-else-on-loop warning

2013-09-17 Thread Skip Montanaro
> But this "else" is useless, isn't it? Just put the "return dt" statement > after the for statement, no else needed. In this particular case, yes, but that's not the point of the post. Pylint doesn't check to see what's in the else clause, only whether there is an early exit from the body of th

Re: [code-quality] Fwd: Spurious useless-else-on-loop warning

2013-09-17 Thread Michael Foord
On 18 September 2013 02:39, Skip Montanaro wrote: > Ned, > > I still think you're missing the point of my original post. A return > is as good as a break when considering early exit from a loop. The > pylint code only checks for the presence of a break statement, but the > test cases clearly show

Re: [code-quality] Fwd: Spurious useless-else-on-loop warning

2013-09-17 Thread Sylvain Thénault
On 18 septembre 05:33, Michael Foord wrote: > On 18 September 2013 02:39, Skip Montanaro wrote: > > I still think you're missing the point of my original post. A return > > is as good as a break when considering early exit from a loop. The > > pylint code only checks for the presence of a break st