[pylint] Fix unreachable infinite loop (PLW0101)#15278
[pylint] Fix unreachable infinite loop (PLW0101)#15278dylwil3 merged 4 commits intoastral-sh:mainfrom
pylint] Fix unreachable infinite loop (PLW0101)#15278Conversation
|
|
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. |
dylwil3
left a comment
There was a problem hiding this comment.
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) |
dylwil3
left a comment
There was a problem hiding this comment.
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.