Open opk12 opened 2 weeks ago
A return statement will exit the function, so the variable of the assignment will never be used. A yield statement does not exit the function, so the variable of the assignment could be used elsewhere.
Good point. For context, I have a custom helper function for non-sequential iteration over Pandas pd.Series
entries. This helper has no other usage of the variable and has the same core structure as test_yield()
(which was actually trimmed down from the helper). OTOH this is not a big deal, so I understand if it's not found to be worth the effort.
We track the number of references to each binding that's created in our semantic model. We could plausibly emit this lint only if the variable being yielded is a local variable that's only ever used in the yield
expression. I think this could be a reasonable rule -- though since it doesn't exist in the original flake8-return
linter, it should probably be a RUF
rule rather than a RET
rule.
@JonathanPlasse would you still object to that version of the rule?
I was not objecting to it. I am open to it.
Okay, great! Was just checking I hadn't missed something that you'd maybe spotted :D
I'll mark this as "accepted" then
Hi, Python newbie here.
test_return()
warns about unnecessary assignment before return, so I was wondering, what about the same, but for yield?