[Python-projects] yield != return
Sylvain Thénault
sylvain.thenault at logilab.fr
Fri Sep 12 09:00:11 CEST 2008
On Tue, Sep 09, 2008 at 09:55:10AM -0500, skip at pobox.com wrote:
> Pylint seems to treat yield statements as if they were returns. They
> definitely seem to be counted the same and the error message emitted with
> too many yields even calls them "returns":
>
> yieldex.py:1: [R, yield_ex] Too many return statements (10/6)
>
> Here's a trivial example cobbled together from an actual (slightly more
> complex) functio which generates a Python function from a higher level
> input:
>
> def yield_ex(s):
> if s:
> yield " line 1: %s\n" % s
> yield " line 2\n"
> yield " line 3\n"
> yield " line 4\n"
> yield " line 5\n"
> else:
> yield " line 6\n"
> yield " line 7\n"
> yield " line 8\n"
> yield " line 9\n"
> yield " line 10\n"
>
> I found it convenient to yield each line of the generated function. The
> code is hardly more complex than the above though there are some parameter
> substitutions on several lines. Having just two yield statements would have
> made it less obvious which values were being substituted where. (Though I
> will admit I could have used dict format expansion.)
>
> At any rate, I don't think yield statements should be counted the same way
> returns are.
True. I've added a ticket: http://www.logilab.oorg/ticket/5977
One possibility is to count subsequent yield as one. Another to don't have
this kind of warning for yield. Opinion ?
--
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