[pylint] Implement stop-iteration-return (PLR1708)#20733
Conversation
ntBre
left a comment
There was a problem hiding this comment.
Thank you! This looks good to me overall, I just had a few fairly small suggestions besides needing to add the test snapshots. Let me know if you need help with that. It might also be good for @amyreese to take a quick look.
I think this is a good rule to add, especially since this pattern will always (?) cause a runtime error on the versions of Python we support.
|
ntBre
left a comment
There was a problem hiding this comment.
Thanks, this is looking good! I noticed that we have a related rule in return-in-generator (B901), and instead of triggering on return statements, it actually runs on function definition statements. Then its visitor looks for both yields and return statements. I think it might make sense to mirror that structure here so that we don't have to traverse multiple scopes looking for an enclosing function. B901 can even avoid visiting nested functions since those will be traversed later by the Checker:
ruff/crates/ruff_linter/src/rules/flake8_bugbear/rules/return_in_generator.rs
Lines 123 to 125 in 766ed5b
501b447 to
451807b
Compare
pylint] Implement stop-iteration-return (PLR1708)
Summary
implement pylint rule stop-iteration-return / R1708
Test Plan