pylint #5977 yield != return [resolved]
skip 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. | |
priority | normal |
---|---|
type | bug |
done in | 0.20.0 |
load | 0.200 |
load left | 0.000 |
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 #9334 C0103 false positive on __class__
- pylint #110235 Support comments after message-control pragmas
Comments
-
2008/09/12 10:18, written by nchauvat
-
2009/01/18 01:14, written by mkiilerich
add commentsee also Maarten's comments in the same thread.
"Maarten's comment" must be http://lists.logilab.org/pipermail/python-projects/2008-September/001516.html