ruff/crates
Dylan a876090715
[internal] Return statements in finally block point to end block for unreachable (PLW0101) (#15276)
Note: `PLW0101` remains in testing rather than preview, so this PR does
not modify any public behavior (hence the title beginning with
`internal` rather than `pylint`, for the sake of the changelog.)

Fixes an error in the processing of `try` statements in the control flow
graph builder.

When processing a try statement, the block following a `return` was
forced to point to the `finally` block. However, if the return was _in_
the `finally` block, this caused the block to point to itself. In the
case where the whole `try-finally` statement was also included inside of
a loop, this caused an infinite loop in the builder for the control flow
graph as it attempted to resolve edges.

Closes #15248

## Test function
### Source
```python
def l():
    while T:
        try:
            while ():
                if 3:
                    break
        finally:
            return
```

### Control Flow Graph
```mermaid
flowchart TD
  start(("Start"))
  return(("End"))
  block0[["`*(empty)*`"]]
  block1[["Loop continue"]]
  block2["return\n"]
  block3[["Loop continue"]]
  block4["break\n"]
  block5["if 3:
                    break\n"]
  block6["while ():
                if 3:
                    break\n"]
  block7[["Exception raised"]]
  block8["try:
            while ():
                if 3:
                    break
        finally:
            return\n"]
  block9["while T:
        try:
            while ():
                if 3:
                    break
        finally:
            return\n"]
  start --> block9
  block9 -- "T" --> block8
  block9 -- "else" --> block0
  block8 -- "Exception raised" --> block7
  block8 -- "else" --> block6
  block7 --> block2
  block6 -- "()" --> block5
  block6 -- "else" --> block2
  block5 -- "3" --> block4
  block5 -- "else" --> block3
  block4 --> block2
  block3 --> block6
  block2 --> return
  block1 --> block9
  block0 --> return
```
2025-01-07 11:26:04 -06:00
..
red_knot Upgrade salsa (#15039) 2024-12-17 15:50:33 +00:00
red_knot_python_semantic [red-knot] Eagerly normalize type[] types (#15272) 2025-01-07 12:53:07 +00:00
red_knot_server Upgrade salsa (#15039) 2024-12-17 15:50:33 +00:00
red_knot_test Attribute panics to the mdtests that cause them (#15241) 2025-01-03 13:45:56 -05:00
red_knot_vendored Sync vendored typeshed stubs (#15213) 2025-01-01 01:14:40 +00:00
red_knot_wasm Rename custom-typeshed-dir, target-version and current-directory CLI options (#14930) 2024-12-13 08:21:52 +00:00
red_knot_workspace Don't special-case class instances in binary expression inference (#15161) 2025-01-06 13:50:20 -05:00
ruff Better error message when --config is given a table key and a non-inline-table value (#15266) 2025-01-06 13:20:28 +00:00
ruff_benchmark Add unused-ignore-comment rule (#15084) 2024-12-23 11:15:28 +01:00
ruff_cache Fix cache key collisions for paths with separators (#12159) 2024-07-03 07:36:46 -05:00
ruff_db Attribute panics to the mdtests that cause them (#15241) 2025-01-03 13:45:56 -05:00
ruff_dev Alternate quotes for strings inside f-strings in preview (#13860) 2024-10-23 07:57:53 +02:00
ruff_diagnostics Show errors for attempted fixes only when passed --verbose (#15237) 2025-01-03 08:50:13 -06:00
ruff_formatter More typos found by codespell (#14880) 2024-12-09 22:47:34 +00:00
ruff_graph type: ignore[codes] and knot: ignore (#15078) 2024-12-23 10:52:43 +01:00
ruff_index [red-knot] small efficiency improvements and bugfixes to use-def map building (#12373) 2024-07-18 09:24:58 -07:00
ruff_linter [internal] Return statements in finally block point to end block for unreachable (PLW0101) (#15276) 2025-01-07 11:26:04 -06:00
ruff_macros [red-knot] Add infrastructure to declare lints (#14873) 2024-12-10 16:14:44 +00:00
ruff_notebook Bump MSRV to Rust 1.80 (#13826) 2024-10-20 10:55:36 +02:00
ruff_python_ast [RUF] Add rule to detect empty literal in deque call (RUF025) (#15104) 2025-01-03 11:57:13 +01:00
ruff_python_ast_integration_tests Update insta snapshots (#14366) 2024-11-15 19:31:15 +01:00
ruff_python_codegen ruff_python_ast: Make Singleton Copy (#14943) 2024-12-12 20:49:54 +01:00
ruff_python_formatter Preserve multiline implicit concatenated strings in docstring positions (#15126) 2025-01-03 10:27:14 +01:00
ruff_python_index Extract LineIndex independent methods from Locator (#13938) 2024-10-28 07:53:41 +00:00
ruff_python_literal Upgrade Rust toolchain to 1.83 (#14677) 2024-11-29 12:05:05 +00:00
ruff_python_parser Modify parsing of raise with cause when exception is absent (#15049) 2024-12-19 13:36:32 +00:00
ruff_python_resolver Update insta snapshots (#14366) 2024-11-15 19:31:15 +01:00
ruff_python_semantic Revert "Add all PEP-585 names to UP006 rule" (#15250) 2025-01-04 12:23:53 +01:00
ruff_python_stdlib Revert "Add all PEP-585 names to UP006 rule" (#15250) 2025-01-04 12:23:53 +01:00
ruff_python_trivia type: ignore[codes] and knot: ignore (#15078) 2024-12-23 10:52:43 +01:00
ruff_python_trivia_integration_tests Update insta snapshots (#14366) 2024-11-15 19:31:15 +01:00
ruff_server Check diagnostic refresh support from client capability (#15014) 2024-12-16 16:26:40 +05:30
ruff_source_file [pyupgrade] Do not report when a UTF-8 comment is followed by a non-UTF-8 one (UP009) (#14728) 2024-12-11 10:30:41 +00:00
ruff_text_size Extract LineIndex independent methods from Locator (#13938) 2024-10-28 07:53:41 +00:00
ruff_wasm Ruff 0.8.6 (#15253) 2025-01-04 13:09:26 +01:00
ruff_workspace [flake8-bugbear] Implement class-as-data-structure (B903) (#9601) 2025-01-06 21:18:28 -06:00