Skip to content
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

Merged
merged 4 commits into from
Jan 8, 2025

Conversation

augustelalande
Copy link
Contributor

@augustelalande augustelalande commented Jan 5, 2025

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.

Copy link
Contributor

github-actions bot commented Jan 5, 2025

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@dylwil3
Copy link
Collaborator

dylwil3 commented Jan 6, 2025

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.

@MichaReiser MichaReiser added bug Something isn't working preview Related to preview mode features labels Jan 6, 2025
@MichaReiser MichaReiser requested a review from dylwil3 January 6, 2025 07:44
Copy link
Collaborator

@dylwil3 dylwil3 left a 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!

@MichaReiser MichaReiser enabled auto-merge (squash) January 8, 2025 07:27
@MichaReiser MichaReiser disabled auto-merge January 8, 2025 08:10
@MichaReiser
Copy link
Member

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)

Copy link
Collaborator

@dylwil3 dylwil3 left a 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!

@dylwil3 dylwil3 merged commit 450d4e0 into astral-sh:main Jan 8, 2025
21 checks passed
@MichaReiser MichaReiser added internal An internal refactor or improvement and removed bug Something isn't working preview Related to preview mode features labels Jan 8, 2025
dcreager added a commit that referenced this pull request Jan 8, 2025
* 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)
@augustelalande augustelalande deleted the unreachable-fix branch January 9, 2025 04:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
internal An internal refactor or improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Freeze when using unreachable rule Long freeze(>3 minutes - probably infinite) when checking file
3 participants