[Python-projects] pylint/astng feature request: unreachable code in generators

Vincent Legoll vincent.legoll at gmail.com
Fri Mar 27 13:51:52 CET 2009


On Fri, Mar 27, 2009 at 11:52 AM, Sylvain Thénault
<sylvain.thenault at logilab.fr> wrote:
> Le Friday 27 March 2009 11:28:59 Vincent Legoll, vous avez écrit :
>> The attached code run through pylint reports:
>>
>> W:  6:gen: Unreachable code
>>
>> but the yield is necessary to have the function turned into a generator
>>
>> I think this case should be handled specifically, and no Warning should be
>> issued, or at least it should be downgraded to "Info" or something, and
>> then the message changed (and the ID too) to something like:
>>
>> "Unreachable yield used for the side effect of turning the method into
>> a generator"
>>
>> But if there is other unreachable code between the raise and the yield, I
>> think this other code could still be flagged as unreachable, the special
>> casing should only be for unreachable yield statements, and maybe even only
>> if there are only nureachable yields in the method...
>
> huum, I'm not sure I'm willing a special case for that. Unless that's a
> current idiom I'm not aware of...
>
> Why not simply using :
>
> def f():
>  return iter(())
>
> why does f has to be a generator ?

Test test code I sent is a simplified version of code used in a
generator-based cooperative multitasking event-loop, which
assumes tasks being generators...

That was only a minimal test-case demonstrating the pylint
message...

I have no doubt we can rewrite the code to not trigger pylint
warning, or shutting pylint up on that particular instance
(which is what I've done, BTW), perhaps not as easy as not
using pylint in the first place, though...

Anyway, I was wrong thinking this being a genuine case of
semi-false positive which could conceivably ask for special-
casing.

-- 
Vincent Legoll


More information about the Python-Projects mailing list