-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[pylint] Fix PLR1708 false positives on nested functions
#21177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
ntBre
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this, but I think the fix here is too simplistic, and we actually need to be traversing scopes. As one example, this code triggers the runtime error in CPython but is no longer flagged by the rule:
>>> def h():
... yield 1
... class C:
... raise StopIteration
... yield C
...
... for i in h(): ...
...
Ellipsis
Traceback (most recent call last):
File "<python-input-0>", line 3, in h
class C:
raise StopIteration
File "<python-input-0>", line 4, in C
raise StopIteration
StopIteration
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<python-input-0>", line 7, in <module>
for i in h(): ...
~^^
RuntimeError: generator raised StopIterationI'm wondering if we should just run the rule on StmtFunctionDefs instead of raise statements and then check for both yield and raise StopIteration while visiting the function body, but I haven't thought about it much more than that.
ntBre
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! This looks good to me now, I just had a couple more minor simplification suggestions.
crates/ruff_linter/src/rules/pylint/rules/stop_iteration_return.rs
Outdated
Show resolved
Hide resolved
crates/ruff_linter/src/rules/pylint/rules/stop_iteration_return.rs
Outdated
Show resolved
Hide resolved
ntBre
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
pylint] Fix PLR1708 false positivespylint] Fix PLR1708 false positives on nested functions
Summary
Fixes #21162
Test Plan
cargo nextest run pylint