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

Sylvain Thénault sylvain.thenault at logilab.fr
Fri Mar 27 11:52:18 CET 2009


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 ?

-- 
Sylvain Thénault                               LOGILAB, Paris (France)
Formations Python, Zope, Plone, Debian:  http://www.logilab.fr/formations
Développement logiciel sur mesure:       http://www.logilab.fr/services
Python et calcul scientifique:           http://www.logilab.fr/science


More information about the Python-Projects mailing list