pylint #5977 yield != return [resolved]
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.
|appeared in||<not specified>|
|closed by||<not specified>|
- pylint #5564 Parameters with leading "_" shouldn't count as "local" variables
- pylint #2467 similarities in the same file are not considered
- pylint #2471 branch count of a function include subfunctions
- pylint #9776 warning if return or break inside a finally
- pylint #4983 new py2.5 check: test "yield" in "try" body with yield in exception handlers.