-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[pylint
] Fix unreachable
infinite loop (PLW0101
)
#15278
Conversation
|
Would it be possible to add a test case that disambiguates this fix from the one in #15276? I believe both of these PRs produce the same CFG for the case in question. |
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.
This is great, thank you!
Let's keep the rule as test for a little longer, and it'd be nice to have add a snapshot that exhibits the new behavior for loops without the presence of a try/finally block (if that's possible?)
Also you may need to rebase against main since I've merged in the PR that fixes the loop if there's a return in a finally
block.
I think with those changes I'd be happy to merge!
I merged in main and reverted the changes that weren't necessary for the fix itself. The only thing that needs doing now is to add a test (if possible) |
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.
Added the latest example from the fuzzer, which passes. So let's merge this in and continue to test this rule and improve the CFG implementation.
Thanks so much for this fix - definitely making progress on this!
* main: [`pylint`] Fix `unreachable` infinite loop (`PLW0101`) (#15278) fix invalid syntax in workflow file (#15357) [`pycodestyle`] Avoid false positives related to type aliases (`E252`) (#15356) [`flake8-builtins`] Disapply `A005` to stub files (#15350) Improve logging system using `logLevel`, avoid trace value (#15232) [`flake8-builtins`] Rename `A005` and improve its error message (#15348) Spruce up docs for pydoclint rules (#15325) [`flake8-type-checking`] Apply `TC008` more eagerly in `TYPE_CHECKING` blocks and disapply it in stubs (#15180) [red-knot] `knot_extensions` Python API (#15103) Display Union of Literals as a Literal (#14993) [red-knot] all types are assignable to object (#15332) [`ruff`] Parenthesize arguments to `int` when removing `int` would change semantics in `unnecessary-cast-to-int` (`RUF046`) (#15277) [`eradicate`] Correctly handle metadata blocks directly followed by normal blocks (`ERA001`) (#15330) Narrowing for class patterns in match statements (#15223) [red-knot] add call checking (#15200) Spruce up docs for `slice-to-remove-prefix-or-suffix` (`FURB188`) (#15328) [`internal`] Return statements in finally block point to end block for `unreachable` (`PLW0101`) (#15276) [`ruff`] Treat `)` as a regex metacharacter (`RUF043`, `RUF055`) (#15318) Use uv consistently throughout the documentation (#15302)
Summary
Fix infinite loop issue reported here #15248. Also re-make rule preview. The issue was caused by the break inside the if block, which caused the flow to exit in an unforeseen way. This caused other issues, eventually leading to an infinite loop.
As stated in #15252 we should do more fuzzing, however I'm not sure which scripts to run so please let me know.
Resolves #15248. Resolves #15336.
Test Plan
Added failing code to fixture.