mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-28 04:45:01 +00:00
![]() 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 ``` |
||
---|---|---|
.. | ||
red_knot | ||
red_knot_python_semantic | ||
red_knot_server | ||
red_knot_test | ||
red_knot_vendored | ||
red_knot_wasm | ||
red_knot_workspace | ||
ruff | ||
ruff_benchmark | ||
ruff_cache | ||
ruff_db | ||
ruff_dev | ||
ruff_diagnostics | ||
ruff_formatter | ||
ruff_graph | ||
ruff_index | ||
ruff_linter | ||
ruff_macros | ||
ruff_notebook | ||
ruff_python_ast | ||
ruff_python_ast_integration_tests | ||
ruff_python_codegen | ||
ruff_python_formatter | ||
ruff_python_index | ||
ruff_python_literal | ||
ruff_python_parser | ||
ruff_python_resolver | ||
ruff_python_semantic | ||
ruff_python_stdlib | ||
ruff_python_trivia | ||
ruff_python_trivia_integration_tests | ||
ruff_server | ||
ruff_source_file | ||
ruff_text_size | ||
ruff_wasm | ||
ruff_workspace |