Skip to content

Commit a389d3a

Browse files
committed
Fix FP, add more test cases
Got to carried away deleting code and deleted the most important comparison to see if what is yielded are the items iterated on. Also added more cases to the test file.
1 parent 7197d97 commit a389d3a

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

pylint/checkers/refactoring/refactoring_checker.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,6 +1137,9 @@ def visit_yield(self, node: nodes.Yield) -> None:
11371137
if not isinstance(parent, nodes.For) or len(parent.body) != 1:
11381138
return
11391139

1140+
if parent.target.name != node.value.name:
1141+
return
1142+
11401143
self.add_message("use-yield-from", node.lineno, node, confidence=HIGH)
11411144

11421145
@staticmethod

tests/functional/u/use/use_yield_from.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# pylint: disable=missing-docstring, import-error
2-
1+
# pylint: disable=missing-docstring, import-error, yield-outside-function
32
import factory
43
from magic import shazam, turbogen
54

5+
yield 1
66

77
def bad(generator):
88
for item in generator:
@@ -37,3 +37,11 @@ def yield_attr_nested():
3737
def yield_expr():
3838
for item in [1, 2, 3]:
3939
yield item # [use-yield-from]
40+
41+
42+
def for_else_yield(gen, something):
43+
for item in gen():
44+
if shazam(item):
45+
break
46+
else:
47+
yield something

0 commit comments

Comments
 (0)