[pylint] Re-implement unreachable (PLW0101) (#10891)

## Summary

This PR re-introduces the control-flow graph implementation which was
first introduced in #5384, and then removed in #9463 due to not being
feature complete. Mainly, it lacked the ability to process
`try`-`except` blocks, along with some more minor bugs.

Closes #8958 and #8959 and #14881.

## Overview of Changes

I will now highlight the major changes implemented in this PR, in order
of implementation.

1. Introduced a post-processing step in loop handling to find any
`continue` or `break` statements within the loop body and redirect them
appropriately.
2. Introduced a loop-continue block which is always placed at the end of
loop blocks, and ensures proper looping regardless of the internal logic
of the block. This resolves #8958.
3. Implemented `try` processing with the following logic (resolves
#8959):
1. In the example below the cfg first encounters a conditional
`ExceptionRaised` forking if an exception was (or will be) raised in the
try block. This is not possible to know (except for trivial cases) so we
assume both paths can be taken unconditionally.
2. Going down the `try` path the cfg goes `try`->`else`->`finally`
unconditionally.
3. Going down the `except` path the cfg will meet several conditional
`ExceptionCaught` which fork depending on the nature of the exception
caught. Again there's no way to know which exceptions may be raised so
both paths are assumed to be taken unconditionally.
4. If none of the exception blocks catch the exception then the cfg
terminates by raising a new exception.
5. A post-processing step is also implemented to redirect any `raises`
or `returns` within the blocks appropriately.
```python
def func():
    try:
        print("try")
    except Exception:
        print("Exception")
    except OtherException as e:
        print("OtherException")
    else:
        print("else")
    finally:
        print("finally")
```
```mermaid
flowchart TD
  start(("Start"))
  return(("End"))
  block0[["`*(empty)*`"]]
  block1["print(#quot;finally#quot;)\n"]
  block2["print(#quot;else#quot;)\n"]
  block3["print(#quot;try#quot;)\n"]
  block4[["Exception raised"]]
  block5["print(#quot;OtherException#quot;)\n"]
  block6["try:
        print(#quot;try#quot;)
    except Exception:
        print(#quot;Exception#quot;)
    except OtherException as e:
        print(#quot;OtherException#quot;)
    else:
        print(#quot;else#quot;)
    finally:
        print(#quot;finally#quot;)\n"]
  block7["print(#quot;Exception#quot;)\n"]
  block8["try:
        print(#quot;try#quot;)
    except Exception:
        print(#quot;Exception#quot;)
    except OtherException as e:
        print(#quot;OtherException#quot;)
    else:
        print(#quot;else#quot;)
    finally:
        print(#quot;finally#quot;)\n"]
  block9["try:
        print(#quot;try#quot;)
    except Exception:
        print(#quot;Exception#quot;)
    except OtherException as e:
        print(#quot;OtherException#quot;)
    else:
        print(#quot;else#quot;)
    finally:
        print(#quot;finally#quot;)\n"]

  start --> block9
  block9 -- "Exception raised" --> block8
  block9 -- "else" --> block3
  block8 -- "Exception" --> block7
  block8 -- "else" --> block6
  block7 --> block1
  block6 -- "OtherException" --> block5
  block6 -- "else" --> block4
  block5 --> block1
  block4 --> return
  block3 --> block2
  block2 --> block1
  block1 --> block0
  block0 --> return
``` 
6. Implemented `with` processing with the following logic:
1. `with` statements have no conditional execution (apart from the
hidden logic handling the enter and exit), so the block is assumed to
execute unconditionally.
2. The one exception is that exceptions raised within the block may
result in control flow resuming at the end of the block. Since it is not
possible know if an exception will be raised, or if it will be handled
by the context manager, we assume that execution always continues after
`with` blocks even if the blocks contain `raise` or `return` statements.
This is handled in a post-processing step.

## Test Plan

Additional test fixtures and control-flow fixtures were added.

---------

Co-authored-by: Micha Reiser <micha@reiser.io>
Co-authored-by: dylwil3 <dylwil3@gmail.com>
This commit is contained in:
Auguste Lalande 2025-01-02 22:54:59 -05:00 committed by GitHub
parent d464ef67cf
commit a3d873ef66
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
25 changed files with 6358 additions and 26 deletions

1
Cargo.lock generated
View file

@ -2768,6 +2768,7 @@ dependencies = [
"regex",
"ruff_cache",
"ruff_diagnostics",
"ruff_index",
"ruff_macros",
"ruff_notebook",
"ruff_python_ast",

View file

@ -15,6 +15,7 @@ license = { workspace = true }
[dependencies]
ruff_cache = { workspace = true }
ruff_diagnostics = { workspace = true, features = ["serde"] }
ruff_index = { workspace = true }
ruff_notebook = { workspace = true }
ruff_macros = { workspace = true }
ruff_python_ast = { workspace = true, features = ["serde", "cache"] }

View file

@ -9,3 +9,29 @@ def func():
def func():
assert False, "oops"
def func():
y = 2
assert y == 2
assert y > 1
assert y < 3
def func():
for i in range(3):
assert i < x
def func():
for j in range(3):
x = 2
else:
assert False
return 1
def func():
for j in range(3):
if j == 2:
print('yay')
break
else:
assert False
return 1

View file

@ -40,8 +40,6 @@ def func():
if True:
break
# TODO(charlie): The `pass` here does not get properly redirected to the top of the
# loop, unlike below.
def func():
for i in range(5):
pass
@ -54,3 +52,59 @@ def func():
else:
return 1
x = 1
def func():
for i in range(5):
pass
else:
pass
def func():
for i in range(3):
if i == 2:
assert i is not None
break
else:
raise Exception()
x = 0
def func():
for i in range(13):
for i in range(12):
x = 2
if True:
break
x = 3
if True:
break
print('hello')
def func():
for i in range(13):
for i in range(12):
x = 2
if True:
continue
x = 3
if True:
break
print('hello')
def func():
for i in range(13):
for i in range(12):
x = 2
if True:
break
x = 3
if True:
continue
print('hello')

View file

@ -106,3 +106,25 @@ def func(self, obj: BytesRep) -> bytes:
self.error(f"can't resolve buffer '{id}'")
return buffer.data
def func(x):
if x == 1:
return 1
elif False:
return 2
elif x == 3:
return 3
elif True:
return 4
elif x == 5:
return 5
elif x == 6:
return 6
def func():
if x:
return
else:
assert x
print('pop')

View file

@ -21,3 +21,14 @@ def func():
i = 0
i += 2
return i
def func():
with x:
i = 0
i = 1
def func():
with x:
i = 0
return 1
i = 1

View file

@ -1,41 +1,118 @@
def func():
try:
...
print("try")
except Exception:
...
print("Exception")
except OtherException as e:
...
print("OtherException")
else:
...
print("else")
finally:
...
print("finally")
def func():
try:
...
except Exception:
...
print("try")
except:
print("Exception")
def func():
try:
...
except Exception:
...
print("try")
except:
print("Exception")
except OtherException as e:
...
print("OtherException")
def func():
try:
...
print("try")
except Exception:
...
print("Exception")
except OtherException as e:
...
print("OtherException")
def func():
try:
print("try")
except Exception:
print("Exception")
except OtherException as e:
print("OtherException")
else:
...
print("else")
def func():
try:
...
print("try")
finally:
...
print("finally")
def func():
try:
return 0
except:
return 1
finally:
return 2
def func():
try:
raise Exception()
except:
print("reached")
def func():
try:
assert False
print("unreachable")
except:
print("reached")
def func():
try:
raise Exception()
finally:
print('reached')
return 2
def func():
try:
assert False
print("unreachable")
finally:
print("reached")
# Test case from ibis caused overflow
def func():
try:
if catalog is not None:
try:
x = 0
except PySparkParseException:
x = 1
try:
x = 2
except PySparkParseException:
x = 3
x = 8
finally:
if catalog is not None:
try:
x = 4
except PySparkParseException:
x = 5
try:
x = 6
except PySparkParseException:
x = 7
def func():
try:
assert False
except ex:
raise ex
finally:
raise Exception("other")

View file

@ -99,12 +99,39 @@ def func():
if True:
break
'''
TODO: because `try` statements aren't handled this triggers a false positive as
the last statement is reached, but the rules thinks it isn't (it doesn't
see/process the break statement).
def func():
while True:
x = 0
x = 1
break
x = 2
x = 3
# Test case found in the Bokeh repository that trigger a false positive.
def func():
while True:
x = 0
x = 1
continue
x = 2
x = 3
def func():
while True:
x = 0
x = 1
return
x = 2
x = 3
def func():
while True:
x = 0
x = 1
raise Exception
x = 2
x = 3
# Test case found in the Bokeh repository that triggered a false positive.
def bokeh2(self, host: str = DEFAULT_HOST, port: int = DEFAULT_PORT) -> None:
self.stop_serving = False
while True:
@ -118,4 +145,3 @@ def bokeh2(self, host: str = DEFAULT_HOST, port: int = DEFAULT_PORT) -> None:
port += 1
self.thread = threading.Thread(target=self._run_web_server)
'''

View file

@ -0,0 +1,263 @@
def after_return():
return "reachable"
return "unreachable"
async def also_works_on_async_functions():
return "reachable"
return "unreachable"
def if_always_true():
if True:
return "reachable"
return "unreachable"
def if_always_false():
if False:
return "unreachable"
return "reachable"
def if_elif_always_false():
if False:
return "unreachable"
elif False:
return "also unreachable"
return "reachable"
def if_elif_always_true():
if False:
return "unreachable"
elif True:
return "reachable"
return "also unreachable"
def ends_with_if():
if False:
return "unreachable"
else:
return "reachable"
def infinite_loop():
while True:
continue
return "unreachable"
''' TODO: we could determine these, but we don't yet.
def for_range_return():
for i in range(10):
if i == 5:
return "reachable"
return "unreachable"
def for_range_else():
for i in range(111):
if i == 5:
return "reachable"
else:
return "unreachable"
return "also unreachable"
def for_range_break():
for i in range(13):
return "reachable"
return "unreachable"
def for_range_if_break():
for i in range(1110):
if True:
return "reachable"
return "unreachable"
'''
def match_wildcard(status):
match status:
case _:
return "reachable"
return "unreachable"
def match_case_and_wildcard(status):
match status:
case 1:
return "reachable"
case _:
return "reachable"
return "unreachable"
def raise_exception():
raise Exception
return "unreachable"
def while_false():
while False:
return "unreachable"
return "reachable"
def while_false_else():
while False:
return "unreachable"
else:
return "reachable"
def while_false_else_return():
while False:
return "unreachable"
else:
return "reachable"
return "also unreachable"
def while_true():
while True:
return "reachable"
return "unreachable"
def while_true_else():
while True:
return "reachable"
else:
return "unreachable"
def while_true_else_return():
while True:
return "reachable"
else:
return "unreachable"
return "also unreachable"
def while_false_var_i():
i = 0
while False:
i += 1
return i
def while_true_var_i():
i = 0
while True:
i += 1
return i
def while_infinite():
while True:
pass
return "unreachable"
def while_if_true():
while True:
if True:
return "reachable"
return "unreachable"
def while_break():
while True:
print("reachable")
break
print("unreachable")
return "reachable"
# Test case found in the Bokeh repository that triggered a false positive.
def bokeh1(self, obj: BytesRep) -> bytes:
data = obj["data"]
if isinstance(data, str):
return base64.b64decode(data)
elif isinstance(data, Buffer):
buffer = data
else:
id = data["id"]
if id in self._buffers:
buffer = self._buffers[id]
else:
self.error(f"can't resolve buffer '{id}'")
return buffer.data
# Test case found in the Bokeh repository that triggered a false positive.
def bokeh2(self, host: str = DEFAULT_HOST, port: int = DEFAULT_PORT) -> None:
self.stop_serving = False
while True:
try:
self.server = HTTPServer((host, port), HtmlOnlyHandler)
self.host = host
self.port = port
break
except OSError:
log.debug(f"port {port} is in use, trying to next one")
port += 1
self.thread = threading.Thread(target=self._run_web_server)
# Test case found in the pandas repository that triggered a false positive.
def _check_basic_constructor(self, empty):
# mat: 2d matrix with shape (3, 2) to input. empty - makes sized
# objects
mat = empty((2, 3), dtype=float)
# 2-D input
frame = DataFrame(mat, columns=["A", "B", "C"], index=[1, 2])
assert len(frame.index) == 2
assert len(frame.columns) == 3
# 1-D input
frame = DataFrame(empty((3,)), columns=["A"], index=[1, 2, 3])
assert len(frame.index) == 3
assert len(frame.columns) == 1
if empty is not np.ones:
msg = r"Cannot convert non-finite values \(NA or inf\) to integer"
with pytest.raises(IntCastingNaNError, match=msg):
DataFrame(mat, columns=["A", "B", "C"], index=[1, 2], dtype=np.int64)
return
else:
frame = DataFrame(
mat, columns=["A", "B", "C"], index=[1, 2], dtype=np.int64
)
assert frame.values.dtype == np.int64
# wrong size axis labels
msg = r"Shape of passed values is \(2, 3\), indices imply \(1, 3\)"
with pytest.raises(ValueError, match=msg):
DataFrame(mat, columns=["A", "B", "C"], index=[1])
msg = r"Shape of passed values is \(2, 3\), indices imply \(2, 2\)"
with pytest.raises(ValueError, match=msg):
DataFrame(mat, columns=["A", "B"], index=[1, 2])
# higher dim raise exception
with pytest.raises(ValueError, match="Must pass 2-d input"):
DataFrame(empty((3, 3, 3)), columns=["A", "B", "C"], index=[1])
# automatic labeling
frame = DataFrame(mat)
tm.assert_index_equal(frame.index, Index(range(2)), exact=True)
tm.assert_index_equal(frame.columns, Index(range(3)), exact=True)
frame = DataFrame(mat, index=[1, 2])
tm.assert_index_equal(frame.columns, Index(range(3)), exact=True)
frame = DataFrame(mat, columns=["A", "B", "C"])
tm.assert_index_equal(frame.index, Index(range(2)), exact=True)
# 0-length axis
frame = DataFrame(empty((0, 3)))
assert len(frame.index) == 0
frame = DataFrame(empty((3, 0)))
assert len(frame.columns) == 0
def after_return():
return "reachable"
print("unreachable")
print("unreachable")
print("unreachable")
print("unreachable")
print("unreachable")
def check_if_url_exists(url: str) -> bool: # type: ignore[return]
return True # uncomment to check URLs
response = requests.head(url, allow_redirects=True)
if response.status_code == 200:
return True
if response.status_code == 404:
return False
console.print(f"[red]Unexpected error received: {response.status_code}[/]")
response.raise_for_status()

View file

@ -366,6 +366,11 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) {
if checker.enabled(Rule::AsyncFunctionWithTimeout) {
flake8_async::rules::async_function_with_timeout(checker, function_def);
}
if checker.enabled(Rule::UnreachableCode) {
checker
.diagnostics
.extend(pylint::rules::in_function(name, body));
}
if checker.enabled(Rule::ReimplementedOperator) {
refurb::rules::reimplemented_operator(checker, &function_def.into());
}

View file

@ -268,6 +268,7 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> {
(Pylint, "R6104") => (RuleGroup::Preview, rules::pylint::rules::NonAugmentedAssignment),
(Pylint, "R6201") => (RuleGroup::Preview, rules::pylint::rules::LiteralMembership),
(Pylint, "R6301") => (RuleGroup::Preview, rules::pylint::rules::NoSelfUse),
(Pylint, "W0101") => (RuleGroup::Preview, rules::pylint::rules::UnreachableCode),
(Pylint, "W0108") => (RuleGroup::Preview, rules::pylint::rules::UnnecessaryLambda),
(Pylint, "W0177") => (RuleGroup::Preview, rules::pylint::rules::NanComparison),
(Pylint, "W0120") => (RuleGroup::Stable, rules::pylint::rules::UselessElseOnLoop),

View file

@ -161,6 +161,7 @@ mod tests {
#[test_case(Rule::UselessImportAlias, Path::new("import_aliasing.py"))]
#[test_case(Rule::UselessReturn, Path::new("useless_return.py"))]
#[test_case(Rule::UselessWithLock, Path::new("useless_with_lock.py"))]
#[test_case(Rule::UnreachableCode, Path::new("unreachable.py"))]
#[test_case(
Rule::YieldFromInAsyncFunction,
Path::new("yield_from_in_async_function.py")

View file

@ -95,6 +95,7 @@ pub(crate) use unnecessary_direct_lambda_call::*;
pub(crate) use unnecessary_dunder_call::*;
pub(crate) use unnecessary_lambda::*;
pub(crate) use unnecessary_list_index_lookup::*;
pub(crate) use unreachable::*;
pub(crate) use unspecified_encoding::*;
pub(crate) use useless_else_on_loop::*;
pub(crate) use useless_exception_statement::*;
@ -201,6 +202,7 @@ mod unnecessary_direct_lambda_call;
mod unnecessary_dunder_call;
mod unnecessary_lambda;
mod unnecessary_list_index_lookup;
mod unreachable;
mod unspecified_encoding;
mod useless_else_on_loop;
mod useless_exception_statement;

View file

@ -0,0 +1,244 @@
---
source: crates/ruff_linter/src/rules/pylint/rules/unreachable.rs
description: "This is a Mermaid graph. You can use https://mermaid.live to visualize it as a diagram."
---
## Function 0
### Source
```python
def func():
assert True
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0[["`*(empty)*`"]]
block1[["Exception raised"]]
block2["assert True\n"]
start --> block2
block2 -- "True" --> block0
block2 -- "else" --> block1
block1 --> return
block0 --> return
```
## Function 1
### Source
```python
def func():
assert False
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0[["`*(empty)*`"]]
block1[["Exception raised"]]
block2["assert False\n"]
start --> block2
block2 -- "False" --> block0
block2 -- "else" --> block1
block1 --> return
block0 --> return
```
## Function 2
### Source
```python
def func():
assert True, "oops"
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0[["`*(empty)*`"]]
block1[["Exception raised"]]
block2["assert True, #quot;oops#quot;\n"]
start --> block2
block2 -- "True" --> block0
block2 -- "else" --> block1
block1 --> return
block0 --> return
```
## Function 3
### Source
```python
def func():
assert False, "oops"
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0[["`*(empty)*`"]]
block1[["Exception raised"]]
block2["assert False, #quot;oops#quot;\n"]
start --> block2
block2 -- "False" --> block0
block2 -- "else" --> block1
block1 --> return
block0 --> return
```
## Function 4
### Source
```python
def func():
y = 2
assert y == 2
assert y > 1
assert y < 3
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0[["`*(empty)*`"]]
block1[["Exception raised"]]
block2["assert y < 3\n"]
block3[["Exception raised"]]
block4["assert y > 1\n"]
block5[["Exception raised"]]
block6["y = 2\nassert y == 2\n"]
start --> block6
block6 -- "y == 2" --> block4
block6 -- "else" --> block5
block5 --> return
block4 -- "y > 1" --> block2
block4 -- "else" --> block3
block3 --> return
block2 -- "y < 3" --> block0
block2 -- "else" --> block1
block1 --> return
block0 --> return
```
## Function 5
### Source
```python
def func():
for i in range(3):
assert i < x
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0[["`*(empty)*`"]]
block1[["Loop continue"]]
block2[["Exception raised"]]
block3["assert i < x\n"]
block4["for i in range(3):
assert i < x\n"]
start --> block4
block4 -- "range(3)" --> block3
block4 -- "else" --> block0
block3 -- "i < x" --> block1
block3 -- "else" --> block2
block2 --> return
block1 --> block4
block0 --> return
```
## Function 6
### Source
```python
def func():
for j in range(3):
x = 2
else:
assert False
return 1
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0["return 1\n"]
block1[["Exception raised"]]
block2["assert False\n"]
block3[["Loop continue"]]
block4["x = 2\n"]
block5["for j in range(3):
x = 2
else:
assert False\n"]
start --> block5
block5 -- "range(3)" --> block4
block5 -- "else" --> block2
block4 --> block3
block3 --> block5
block2 -- "False" --> block0
block2 -- "else" --> block1
block1 --> return
block0 --> return
```
## Function 7
### Source
```python
def func():
for j in range(3):
if j == 2:
print('yay')
break
else:
assert False
return 1
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0["return 1\n"]
block1[["Exception raised"]]
block2["assert False\n"]
block3[["Loop continue"]]
block4["print('yay')\nbreak\n"]
block5["if j == 2:
print('yay')
break\n"]
block6["for j in range(3):
if j == 2:
print('yay')
break
else:
assert False\n"]
start --> block6
block6 -- "range(3)" --> block5
block6 -- "else" --> block2
block5 -- "j == 2" --> block4
block5 -- "else" --> block3
block4 --> block0
block3 --> block6
block2 -- "False" --> block0
block2 -- "else" --> block1
block1 --> return
block0 --> return
```

View file

@ -0,0 +1,257 @@
---
source: crates/ruff_linter/src/rules/pylint/rules/unreachable.rs
description: "This is a Mermaid graph. You can use https://mermaid.live to visualize it as a diagram."
---
## Function 0
### Source
```python
def func():
async for i in range(5):
print(i)
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0[["`*(empty)*`"]]
block1[["Loop continue"]]
block2["print(i)\n"]
block3["async for i in range(5):
print(i)\n"]
start --> block3
block3 -- "range(5)" --> block2
block3 -- "else" --> block0
block2 --> block1
block1 --> block3
block0 --> return
```
## Function 1
### Source
```python
def func():
async for i in range(20):
print(i)
else:
return 0
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0[["`*(empty)*`"]]
block1["return 0\n"]
block2[["Loop continue"]]
block3["print(i)\n"]
block4["async for i in range(20):
print(i)
else:
return 0\n"]
start --> block4
block4 -- "range(20)" --> block3
block4 -- "else" --> block1
block3 --> block2
block2 --> block4
block1 --> return
block0 --> return
```
## Function 2
### Source
```python
def func():
async for i in range(10):
if i == 5:
return 1
return 0
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0["return 0\n"]
block1[["Loop continue"]]
block2["return 1\n"]
block3["if i == 5:
return 1\n"]
block4["async for i in range(10):
if i == 5:
return 1\n"]
start --> block4
block4 -- "range(10)" --> block3
block4 -- "else" --> block0
block3 -- "i == 5" --> block2
block3 -- "else" --> block1
block2 --> return
block1 --> block4
block0 --> return
```
## Function 3
### Source
```python
def func():
async for i in range(111):
if i == 5:
return 1
else:
return 0
return 2
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0["return 2\n"]
block1["return 0\n"]
block2[["Loop continue"]]
block3["return 1\n"]
block4["if i == 5:
return 1\n"]
block5["async for i in range(111):
if i == 5:
return 1
else:
return 0\n"]
start --> block5
block5 -- "range(111)" --> block4
block5 -- "else" --> block1
block4 -- "i == 5" --> block3
block4 -- "else" --> block2
block3 --> return
block2 --> block5
block1 --> return
block0 --> return
```
## Function 4
### Source
```python
def func():
async for i in range(12):
continue
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0[["`*(empty)*`"]]
block1[["Loop continue"]]
block2["continue\n"]
block3["async for i in range(12):
continue\n"]
start --> block3
block3 -- "range(12)" --> block2
block3 -- "else" --> block0
block2 --> block3
block1 --> block3
block0 --> return
```
## Function 5
### Source
```python
def func():
async for i in range(1110):
if True:
continue
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0[["`*(empty)*`"]]
block1[["Loop continue"]]
block2["continue\n"]
block3["if True:
continue\n"]
block4["async for i in range(1110):
if True:
continue\n"]
start --> block4
block4 -- "range(1110)" --> block3
block4 -- "else" --> block0
block3 -- "True" --> block2
block3 -- "else" --> block1
block2 --> block4
block1 --> block4
block0 --> return
```
## Function 6
### Source
```python
def func():
async for i in range(13):
break
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0[["`*(empty)*`"]]
block1[["Loop continue"]]
block2["break\n"]
block3["async for i in range(13):
break\n"]
start --> block3
block3 -- "range(13)" --> block2
block3 -- "else" --> block0
block2 --> return
block1 --> block3
block0 --> return
```
## Function 7
### Source
```python
def func():
async for i in range(1110):
if True:
break
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0[["`*(empty)*`"]]
block1[["Loop continue"]]
block2["break\n"]
block3["if True:
break\n"]
block4["async for i in range(1110):
if True:
break\n"]
start --> block4
block4 -- "range(1110)" --> block3
block4 -- "else" --> block0
block3 -- "True" --> block2
block3 -- "else" --> block1
block2 --> return
block1 --> block4
block0 --> return
```

View file

@ -0,0 +1,590 @@
---
source: crates/ruff_linter/src/rules/pylint/rules/unreachable.rs
description: "This is a Mermaid graph. You can use https://mermaid.live to visualize it as a diagram."
---
## Function 0
### Source
```python
def func():
for i in range(5):
print(i)
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0[["`*(empty)*`"]]
block1[["Loop continue"]]
block2["print(i)\n"]
block3["for i in range(5):
print(i)\n"]
start --> block3
block3 -- "range(5)" --> block2
block3 -- "else" --> block0
block2 --> block1
block1 --> block3
block0 --> return
```
## Function 1
### Source
```python
def func():
for i in range(20):
print(i)
else:
return 0
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0[["`*(empty)*`"]]
block1["return 0\n"]
block2[["Loop continue"]]
block3["print(i)\n"]
block4["for i in range(20):
print(i)
else:
return 0\n"]
start --> block4
block4 -- "range(20)" --> block3
block4 -- "else" --> block1
block3 --> block2
block2 --> block4
block1 --> return
block0 --> return
```
## Function 2
### Source
```python
def func():
for i in range(10):
if i == 5:
return 1
return 0
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0["return 0\n"]
block1[["Loop continue"]]
block2["return 1\n"]
block3["if i == 5:
return 1\n"]
block4["for i in range(10):
if i == 5:
return 1\n"]
start --> block4
block4 -- "range(10)" --> block3
block4 -- "else" --> block0
block3 -- "i == 5" --> block2
block3 -- "else" --> block1
block2 --> return
block1 --> block4
block0 --> return
```
## Function 3
### Source
```python
def func():
for i in range(111):
if i == 5:
return 1
else:
return 0
return 2
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0["return 2\n"]
block1["return 0\n"]
block2[["Loop continue"]]
block3["return 1\n"]
block4["if i == 5:
return 1\n"]
block5["for i in range(111):
if i == 5:
return 1
else:
return 0\n"]
start --> block5
block5 -- "range(111)" --> block4
block5 -- "else" --> block1
block4 -- "i == 5" --> block3
block4 -- "else" --> block2
block3 --> return
block2 --> block5
block1 --> return
block0 --> return
```
## Function 4
### Source
```python
def func():
for i in range(12):
continue
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0[["`*(empty)*`"]]
block1[["Loop continue"]]
block2["continue\n"]
block3["for i in range(12):
continue\n"]
start --> block3
block3 -- "range(12)" --> block2
block3 -- "else" --> block0
block2 --> block3
block1 --> block3
block0 --> return
```
## Function 5
### Source
```python
def func():
for i in range(1110):
if True:
continue
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0[["`*(empty)*`"]]
block1[["Loop continue"]]
block2["continue\n"]
block3["if True:
continue\n"]
block4["for i in range(1110):
if True:
continue\n"]
start --> block4
block4 -- "range(1110)" --> block3
block4 -- "else" --> block0
block3 -- "True" --> block2
block3 -- "else" --> block1
block2 --> block4
block1 --> block4
block0 --> return
```
## Function 6
### Source
```python
def func():
for i in range(13):
break
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0[["`*(empty)*`"]]
block1[["Loop continue"]]
block2["break\n"]
block3["for i in range(13):
break\n"]
start --> block3
block3 -- "range(13)" --> block2
block3 -- "else" --> block0
block2 --> return
block1 --> block3
block0 --> return
```
## Function 7
### Source
```python
def func():
for i in range(1110):
if True:
break
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0[["`*(empty)*`"]]
block1[["Loop continue"]]
block2["break\n"]
block3["if True:
break\n"]
block4["for i in range(1110):
if True:
break\n"]
start --> block4
block4 -- "range(1110)" --> block3
block4 -- "else" --> block0
block3 -- "True" --> block2
block3 -- "else" --> block1
block2 --> return
block1 --> block4
block0 --> return
```
## Function 8
### Source
```python
def func():
for i in range(5):
pass
else:
return 1
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0[["`*(empty)*`"]]
block1["return 1\n"]
block2[["Loop continue"]]
block3["pass\n"]
block4["for i in range(5):
pass
else:
return 1\n"]
start --> block4
block4 -- "range(5)" --> block3
block4 -- "else" --> block1
block3 --> block2
block2 --> block4
block1 --> return
block0 --> return
```
## Function 9
### Source
```python
def func():
for i in range(5):
pass
else:
return 1
x = 1
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0["x = 1\n"]
block1["return 1\n"]
block2[["Loop continue"]]
block3["pass\n"]
block4["for i in range(5):
pass
else:
return 1\n"]
start --> block4
block4 -- "range(5)" --> block3
block4 -- "else" --> block1
block3 --> block2
block2 --> block4
block1 --> return
block0 --> return
```
## Function 10
### Source
```python
def func():
for i in range(5):
pass
else:
pass
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0[["`*(empty)*`"]]
block1["pass\n"]
block2[["Loop continue"]]
block3["pass\n"]
block4["for i in range(5):
pass
else:
pass\n"]
start --> block4
block4 -- "range(5)" --> block3
block4 -- "else" --> block1
block3 --> block2
block2 --> block4
block1 --> block0
block0 --> return
```
## Function 11
### Source
```python
def func():
for i in range(3):
if i == 2:
assert i is not None
break
else:
raise Exception()
x = 0
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0["x = 0\n"]
block1[["Exception raised"]]
block2["raise Exception()\n"]
block3[["Loop continue"]]
block4["break\n"]
block5[["Exception raised"]]
block6["assert i is not None\n"]
block7["if i == 2:
assert i is not None
break\n"]
block8["for i in range(3):
if i == 2:
assert i is not None
break
else:
raise Exception()\n"]
start --> block8
block8 -- "range(3)" --> block7
block8 -- "else" --> block2
block7 -- "i == 2" --> block6
block7 -- "else" --> block3
block6 -- "i is not None" --> block4
block6 -- "else" --> block5
block5 --> return
block4 --> block0
block3 --> block8
block2 --> block1
block1 --> return
block0 --> return
```
## Function 12
### Source
```python
def func():
for i in range(13):
for i in range(12):
x = 2
if True:
break
x = 3
if True:
break
print('hello')
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0["print('hello')\n"]
block1[["Loop continue"]]
block2["break\n"]
block3["x = 3\nif True:
break\n"]
block4[["Loop continue"]]
block5["break\n"]
block6["x = 2\nif True:
break\n"]
block7["for i in range(12):
x = 2
if True:
break\n"]
block8["for i in range(13):
for i in range(12):
x = 2
if True:
break
x = 3
if True:
break\n"]
start --> block8
block8 -- "range(13)" --> block7
block8 -- "else" --> block0
block7 -- "range(12)" --> block6
block7 -- "else" --> block3
block6 -- "True" --> block5
block6 -- "else" --> block4
block5 --> block3
block4 --> block7
block3 -- "True" --> block2
block3 -- "else" --> block1
block2 --> block0
block1 --> block8
block0 --> return
```
## Function 13
### Source
```python
def func():
for i in range(13):
for i in range(12):
x = 2
if True:
continue
x = 3
if True:
break
print('hello')
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0["print('hello')\n"]
block1[["Loop continue"]]
block2["break\n"]
block3["x = 3\nif True:
break\n"]
block4[["Loop continue"]]
block5["continue\n"]
block6["x = 2\nif True:
continue\n"]
block7["for i in range(12):
x = 2
if True:
continue\n"]
block8["for i in range(13):
for i in range(12):
x = 2
if True:
continue
x = 3
if True:
break\n"]
start --> block8
block8 -- "range(13)" --> block7
block8 -- "else" --> block0
block7 -- "range(12)" --> block6
block7 -- "else" --> block3
block6 -- "True" --> block5
block6 -- "else" --> block4
block5 --> block7
block4 --> block7
block3 -- "True" --> block2
block3 -- "else" --> block1
block2 --> block0
block1 --> block8
block0 --> return
```
## Function 14
### Source
```python
def func():
for i in range(13):
for i in range(12):
x = 2
if True:
break
x = 3
if True:
continue
print('hello')
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0["print('hello')\n"]
block1[["Loop continue"]]
block2["continue\n"]
block3["x = 3\nif True:
continue\n"]
block4[["Loop continue"]]
block5["break\n"]
block6["x = 2\nif True:
break\n"]
block7["for i in range(12):
x = 2
if True:
break\n"]
block8["for i in range(13):
for i in range(12):
x = 2
if True:
break
x = 3
if True:
continue\n"]
start --> block8
block8 -- "range(13)" --> block7
block8 -- "else" --> block0
block7 -- "range(12)" --> block6
block7 -- "else" --> block3
block6 -- "True" --> block5
block6 -- "else" --> block4
block5 --> block3
block4 --> block7
block3 -- "True" --> block2
block3 -- "else" --> block1
block2 --> block8
block1 --> block8
block0 --> return
```

View file

@ -0,0 +1,720 @@
---
source: crates/ruff_linter/src/rules/pylint/rules/unreachable.rs
description: "This is a Mermaid graph. You can use https://mermaid.live to visualize it as a diagram."
---
## Function 0
### Source
```python
def func():
if False:
return 0
return 1
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0["return 1\n"]
block1["return 0\n"]
block2["if False:
return 0\n"]
start --> block2
block2 -- "False" --> block1
block2 -- "else" --> block0
block1 --> return
block0 --> return
```
## Function 1
### Source
```python
def func():
if True:
return 1
return 0
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0["return 0\n"]
block1["return 1\n"]
block2["if True:
return 1\n"]
start --> block2
block2 -- "True" --> block1
block2 -- "else" --> block0
block1 --> return
block0 --> return
```
## Function 2
### Source
```python
def func():
if False:
return 0
else:
return 1
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0[["`*(empty)*`"]]
block1["return 0\n"]
block2["return 1\n"]
block3["if False:
return 0
else:
return 1\n"]
start --> block3
block3 -- "False" --> block1
block3 -- "else" --> block2
block2 --> return
block1 --> return
block0 --> return
```
## Function 3
### Source
```python
def func():
if True:
return 1
else:
return 0
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0[["`*(empty)*`"]]
block1["return 1\n"]
block2["return 0\n"]
block3["if True:
return 1
else:
return 0\n"]
start --> block3
block3 -- "True" --> block1
block3 -- "else" --> block2
block2 --> return
block1 --> return
block0 --> return
```
## Function 4
### Source
```python
def func():
if False:
return 0
else:
return 1
return "unreachable"
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0["return #quot;unreachable#quot;\n"]
block1["return 0\n"]
block2["return 1\n"]
block3["if False:
return 0
else:
return 1\n"]
start --> block3
block3 -- "False" --> block1
block3 -- "else" --> block2
block2 --> return
block1 --> return
block0 --> return
```
## Function 5
### Source
```python
def func():
if True:
return 1
else:
return 0
return "unreachable"
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0["return #quot;unreachable#quot;\n"]
block1["return 1\n"]
block2["return 0\n"]
block3["if True:
return 1
else:
return 0\n"]
start --> block3
block3 -- "True" --> block1
block3 -- "else" --> block2
block2 --> return
block1 --> return
block0 --> return
```
## Function 6
### Source
```python
def func():
if True:
if True:
return 1
return 2
else:
return 3
return "unreachable2"
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0["return #quot;unreachable2#quot;\n"]
block1["return 2\n"]
block2["return 1\n"]
block3["if True:
return 1\n"]
block4["return 3\n"]
block5["if True:
if True:
return 1
return 2
else:
return 3\n"]
start --> block5
block5 -- "True" --> block3
block5 -- "else" --> block4
block4 --> return
block3 -- "True" --> block2
block3 -- "else" --> block1
block2 --> return
block1 --> return
block0 --> return
```
## Function 7
### Source
```python
def func():
if False:
return 0
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0[["`*(empty)*`"]]
block1["return 0\n"]
block2["if False:
return 0\n"]
start --> block2
block2 -- "False" --> block1
block2 -- "else" --> block0
block1 --> return
block0 --> return
```
## Function 8
### Source
```python
def func():
if True:
return 1
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0[["`*(empty)*`"]]
block1["return 1\n"]
block2["if True:
return 1\n"]
start --> block2
block2 -- "True" --> block1
block2 -- "else" --> block0
block1 --> return
block0 --> return
```
## Function 9
### Source
```python
def func():
if True:
return 1
elif False:
return 2
else:
return 0
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0[["`*(empty)*`"]]
block1["return 1\n"]
block2["return 0\n"]
block3["return 2\n"]
block4["if True:
return 1
elif False:
return 2
else:
return 0\n"]
block5["if True:
return 1
elif False:
return 2
else:
return 0\n"]
start --> block5
block5 -- "True" --> block1
block5 -- "else" --> block4
block4 -- "False" --> block3
block4 -- "else" --> block2
block3 --> return
block2 --> return
block1 --> return
block0 --> return
```
## Function 10
### Source
```python
def func():
if False:
return 1
elif True:
return 2
else:
return 0
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0[["`*(empty)*`"]]
block1["return 1\n"]
block2["return 0\n"]
block3["return 2\n"]
block4["if False:
return 1
elif True:
return 2
else:
return 0\n"]
block5["if False:
return 1
elif True:
return 2
else:
return 0\n"]
start --> block5
block5 -- "False" --> block1
block5 -- "else" --> block4
block4 -- "True" --> block3
block4 -- "else" --> block2
block3 --> return
block2 --> return
block1 --> return
block0 --> return
```
## Function 11
### Source
```python
def func():
if True:
if False:
return 0
elif True:
return 1
else:
return 2
return 3
elif True:
return 4
else:
return 5
return 6
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0["return 6\n"]
block1["return 3\n"]
block2["return 0\n"]
block3["return 2\n"]
block4["return 1\n"]
block5["if False:
return 0
elif True:
return 1
else:
return 2\n"]
block6["if False:
return 0
elif True:
return 1
else:
return 2\n"]
block7["return 5\n"]
block8["return 4\n"]
block9["if True:
if False:
return 0
elif True:
return 1
else:
return 2
return 3
elif True:
return 4
else:
return 5\n"]
block10["if True:
if False:
return 0
elif True:
return 1
else:
return 2
return 3
elif True:
return 4
else:
return 5\n"]
start --> block10
block10 -- "True" --> block6
block10 -- "else" --> block9
block9 -- "True" --> block8
block9 -- "else" --> block7
block8 --> return
block7 --> return
block6 -- "False" --> block2
block6 -- "else" --> block5
block5 -- "True" --> block4
block5 -- "else" --> block3
block4 --> return
block3 --> return
block2 --> return
block1 --> return
block0 --> return
```
## Function 12
### Source
```python
def func():
if False:
return "unreached"
elif False:
return "also unreached"
return "reached"
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0["return #quot;reached#quot;\n"]
block1["return #quot;unreached#quot;\n"]
block2["return #quot;also unreached#quot;\n"]
block3["if False:
return #quot;unreached#quot;
elif False:
return #quot;also unreached#quot;\n"]
block4["if False:
return #quot;unreached#quot;
elif False:
return #quot;also unreached#quot;\n"]
start --> block4
block4 -- "False" --> block1
block4 -- "else" --> block3
block3 -- "False" --> block2
block3 -- "else" --> block0
block2 --> return
block1 --> return
block0 --> return
```
## Function 13
### Source
```python
def func(self, obj: BytesRep) -> bytes:
data = obj["data"]
if isinstance(data, str):
return base64.b64decode(data)
elif isinstance(data, Buffer):
buffer = data
else:
id = data["id"]
if id in self._buffers:
buffer = self._buffers[id]
else:
self.error(f"can't resolve buffer '{id}'")
return buffer.data
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0["return buffer.data\n"]
block1["return base64.b64decode(data)\n"]
block2["buffer = self._buffers[id]\n"]
block3["self.error(f#quot;can't resolve buffer '{id}'#quot;)\n"]
block4["id = data[#quot;id#quot;]\nif id in self._buffers:
buffer = self._buffers[id]
else:
self.error(f#quot;can't resolve buffer '{id}'#quot;)\n"]
block5["buffer = data\n"]
block6["if isinstance(data, str):
return base64.b64decode(data)
elif isinstance(data, Buffer):
buffer = data
else:
id = data[#quot;id#quot;]
if id in self._buffers:
buffer = self._buffers[id]
else:
self.error(f#quot;can't resolve buffer '{id}'#quot;)\n"]
block7["data = obj[#quot;data#quot;]\nif isinstance(data, str):
return base64.b64decode(data)
elif isinstance(data, Buffer):
buffer = data
else:
id = data[#quot;id#quot;]
if id in self._buffers:
buffer = self._buffers[id]
else:
self.error(f#quot;can't resolve buffer '{id}'#quot;)\n"]
start --> block7
block7 -- "isinstance(data, str)" --> block1
block7 -- "else" --> block6
block6 -- "isinstance(data, Buffer)" --> block5
block6 -- "else" --> block4
block5 --> block0
block4 -- "id in self._buffers" --> block2
block4 -- "else" --> block3
block3 --> block0
block2 --> block0
block1 --> return
block0 --> return
```
## Function 14
### Source
```python
def func(x):
if x == 1:
return 1
elif False:
return 2
elif x == 3:
return 3
elif True:
return 4
elif x == 5:
return 5
elif x == 6:
return 6
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0[["`*(empty)*`"]]
block1["return 1\n"]
block2["return 6\n"]
block3["if x == 1:
return 1
elif False:
return 2
elif x == 3:
return 3
elif True:
return 4
elif x == 5:
return 5
elif x == 6:
return 6\n"]
block4["return 5\n"]
block5["if x == 1:
return 1
elif False:
return 2
elif x == 3:
return 3
elif True:
return 4
elif x == 5:
return 5
elif x == 6:
return 6\n"]
block6["return 4\n"]
block7["if x == 1:
return 1
elif False:
return 2
elif x == 3:
return 3
elif True:
return 4
elif x == 5:
return 5
elif x == 6:
return 6\n"]
block8["return 3\n"]
block9["if x == 1:
return 1
elif False:
return 2
elif x == 3:
return 3
elif True:
return 4
elif x == 5:
return 5
elif x == 6:
return 6\n"]
block10["return 2\n"]
block11["if x == 1:
return 1
elif False:
return 2
elif x == 3:
return 3
elif True:
return 4
elif x == 5:
return 5
elif x == 6:
return 6\n"]
block12["if x == 1:
return 1
elif False:
return 2
elif x == 3:
return 3
elif True:
return 4
elif x == 5:
return 5
elif x == 6:
return 6\n"]
start --> block12
block12 -- "x == 1" --> block1
block12 -- "else" --> block11
block11 -- "False" --> block10
block11 -- "else" --> block9
block10 --> return
block9 -- "x == 3" --> block8
block9 -- "else" --> block7
block8 --> return
block7 -- "True" --> block6
block7 -- "else" --> block5
block6 --> return
block5 -- "x == 5" --> block4
block5 -- "else" --> block3
block4 --> return
block3 -- "x == 6" --> block2
block3 -- "else" --> block0
block2 --> return
block1 --> return
block0 --> return
```
## Function 15
### Source
```python
def func():
if x:
return
else:
assert x
print('pop')
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0["print('pop')\n"]
block1["return\n"]
block2[["Exception raised"]]
block3["assert x\n"]
block4["if x:
return
else:
assert x\n"]
start --> block4
block4 -- "x" --> block1
block4 -- "else" --> block3
block3 -- "x" --> block0
block3 -- "else" --> block2
block2 --> return
block1 --> return
block0 --> return
```

View file

@ -0,0 +1,823 @@
---
source: crates/ruff_linter/src/rules/pylint/rules/unreachable.rs
description: "This is a Mermaid graph. You can use https://mermaid.live to visualize it as a diagram."
---
## Function 0
### Source
```python
def func(status):
match status:
case _:
return 0
return "unreachable"
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0["return #quot;unreachable#quot;\n"]
block1["return 0\n"]
block2["match status:
case _:
return 0\n"]
start --> block2
block2 --> block1
block1 --> return
block0 --> return
```
## Function 1
### Source
```python
def func(status):
match status:
case 1:
return 1
return 0
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0["return 0\n"]
block1["return 1\n"]
block2["match status:
case 1:
return 1\n"]
start --> block2
block2 -- "case 1" --> block1
block2 -- "else" --> block0
block1 --> return
block0 --> return
```
## Function 2
### Source
```python
def func(status):
match status:
case 1:
return 1
case _:
return 0
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0[["`*(empty)*`"]]
block1["return 0\n"]
block2["match status:
case 1:
return 1
case _:
return 0\n"]
block3["return 1\n"]
block4["match status:
case 1:
return 1
case _:
return 0\n"]
start --> block4
block4 -- "case 1" --> block3
block4 -- "else" --> block2
block3 --> return
block2 --> block1
block1 --> return
block0 --> return
```
## Function 3
### Source
```python
def func(status):
match status:
case 1 | 2 | 3:
return 5
return 6
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0["return 6\n"]
block1["return 5\n"]
block2["match status:
case 1 | 2 | 3:
return 5\n"]
start --> block2
block2 -- "case 1 | 2 | 3" --> block1
block2 -- "else" --> block0
block1 --> return
block0 --> return
```
## Function 4
### Source
```python
def func(status):
match status:
case 1 | 2 | 3:
return 5
case _:
return 10
return 0
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0["return 0\n"]
block1["return 10\n"]
block2["match status:
case 1 | 2 | 3:
return 5
case _:
return 10\n"]
block3["return 5\n"]
block4["match status:
case 1 | 2 | 3:
return 5
case _:
return 10\n"]
start --> block4
block4 -- "case 1 | 2 | 3" --> block3
block4 -- "else" --> block2
block3 --> return
block2 --> block1
block1 --> return
block0 --> return
```
## Function 5
### Source
```python
def func(status):
match status:
case 0:
return 0
case 1:
return 1
case 1:
return "1 again"
case _:
return 3
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0[["`*(empty)*`"]]
block1["return 3\n"]
block2["match status:
case 0:
return 0
case 1:
return 1
case 1:
return #quot;1 again#quot;
case _:
return 3\n"]
block3["return #quot;1 again#quot;\n"]
block4["match status:
case 0:
return 0
case 1:
return 1
case 1:
return #quot;1 again#quot;
case _:
return 3\n"]
block5["return 1\n"]
block6["match status:
case 0:
return 0
case 1:
return 1
case 1:
return #quot;1 again#quot;
case _:
return 3\n"]
block7["return 0\n"]
block8["match status:
case 0:
return 0
case 1:
return 1
case 1:
return #quot;1 again#quot;
case _:
return 3\n"]
start --> block8
block8 -- "case 0" --> block7
block8 -- "else" --> block6
block7 --> return
block6 -- "case 1" --> block5
block6 -- "else" --> block4
block5 --> return
block4 -- "case 1" --> block3
block4 -- "else" --> block2
block3 --> return
block2 --> block1
block1 --> return
block0 --> return
```
## Function 6
### Source
```python
def func(status):
i = 0
match status, i:
case _, _:
return 0
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0[["`*(empty)*`"]]
block1["return 0\n"]
block2["match status, i:
case _, _:
return 0\n"]
block3["i = 0\n"]
start --> block3
block3 --> block2
block2 -- "case _, _" --> block1
block2 -- "else" --> block0
block1 --> return
block0 --> return
```
## Function 7
### Source
```python
def func(status):
i = 0
match status, i:
case _, 0:
return 0
case _, 2:
return 0
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0[["`*(empty)*`"]]
block1["return 0\n"]
block2["match status, i:
case _, 0:
return 0
case _, 2:
return 0\n"]
block3["return 0\n"]
block4["match status, i:
case _, 0:
return 0
case _, 2:
return 0\n"]
block5["i = 0\n"]
start --> block5
block5 --> block4
block4 -- "case _, 0" --> block3
block4 -- "else" --> block2
block3 --> return
block2 -- "case _, 2" --> block1
block2 -- "else" --> block0
block1 --> return
block0 --> return
```
## Function 8
### Source
```python
def func(point):
match point:
case (0, 0):
print("Origin")
case _:
raise ValueError("oops")
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0[["`*(empty)*`"]]
block1[["Exception raised"]]
block2["raise ValueError(#quot;oops#quot;)\n"]
block3["match point:
case (0, 0):
print(#quot;Origin#quot;)
case _:
raise ValueError(#quot;oops#quot;)\n"]
block4["print(#quot;Origin#quot;)\n"]
block5["match point:
case (0, 0):
print(#quot;Origin#quot;)
case _:
raise ValueError(#quot;oops#quot;)\n"]
start --> block5
block5 -- "case (0, 0)" --> block4
block5 -- "else" --> block3
block4 --> block0
block3 --> block2
block2 --> block1
block1 --> return
block0 --> return
```
## Function 9
### Source
```python
def func(point):
match point:
case (0, 0):
print("Origin")
case (0, y):
print(f"Y={y}")
case (x, 0):
print(f"X={x}")
case (x, y):
print(f"X={x}, Y={y}")
case _:
raise ValueError("Not a point")
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0[["`*(empty)*`"]]
block1[["Exception raised"]]
block2["raise ValueError(#quot;Not a point#quot;)\n"]
block3["match point:
case (0, 0):
print(#quot;Origin#quot;)
case (0, y):
print(f#quot;Y={y}#quot;)
case (x, 0):
print(f#quot;X={x}#quot;)
case (x, y):
print(f#quot;X={x}, Y={y}#quot;)
case _:
raise ValueError(#quot;Not a point#quot;)\n"]
block4["print(f#quot;X={x}, Y={y}#quot;)\n"]
block5["match point:
case (0, 0):
print(#quot;Origin#quot;)
case (0, y):
print(f#quot;Y={y}#quot;)
case (x, 0):
print(f#quot;X={x}#quot;)
case (x, y):
print(f#quot;X={x}, Y={y}#quot;)
case _:
raise ValueError(#quot;Not a point#quot;)\n"]
block6["print(f#quot;X={x}#quot;)\n"]
block7["match point:
case (0, 0):
print(#quot;Origin#quot;)
case (0, y):
print(f#quot;Y={y}#quot;)
case (x, 0):
print(f#quot;X={x}#quot;)
case (x, y):
print(f#quot;X={x}, Y={y}#quot;)
case _:
raise ValueError(#quot;Not a point#quot;)\n"]
block8["print(f#quot;Y={y}#quot;)\n"]
block9["match point:
case (0, 0):
print(#quot;Origin#quot;)
case (0, y):
print(f#quot;Y={y}#quot;)
case (x, 0):
print(f#quot;X={x}#quot;)
case (x, y):
print(f#quot;X={x}, Y={y}#quot;)
case _:
raise ValueError(#quot;Not a point#quot;)\n"]
block10["print(#quot;Origin#quot;)\n"]
block11["match point:
case (0, 0):
print(#quot;Origin#quot;)
case (0, y):
print(f#quot;Y={y}#quot;)
case (x, 0):
print(f#quot;X={x}#quot;)
case (x, y):
print(f#quot;X={x}, Y={y}#quot;)
case _:
raise ValueError(#quot;Not a point#quot;)\n"]
start --> block11
block11 -- "case (0, 0)" --> block10
block11 -- "else" --> block9
block10 --> block0
block9 -- "case (0, y)" --> block8
block9 -- "else" --> block7
block8 --> block0
block7 -- "case (x, 0)" --> block6
block7 -- "else" --> block5
block6 --> block0
block5 -- "case (x, y)" --> block4
block5 -- "else" --> block3
block4 --> block0
block3 --> block2
block2 --> block1
block1 --> return
block0 --> return
```
## Function 10
### Source
```python
def where_is(point):
class Point:
x: int
y: int
match point:
case Point(x=0, y=0):
print("Origin")
case Point(x=0, y=y):
print(f"Y={y}")
case Point(x=x, y=0):
print(f"X={x}")
case Point():
print("Somewhere else")
case _:
print("Not a point")
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0[["`*(empty)*`"]]
block1["print(#quot;Not a point#quot;)\n"]
block2["match point:
case Point(x=0, y=0):
print(#quot;Origin#quot;)
case Point(x=0, y=y):
print(f#quot;Y={y}#quot;)
case Point(x=x, y=0):
print(f#quot;X={x}#quot;)
case Point():
print(#quot;Somewhere else#quot;)
case _:
print(#quot;Not a point#quot;)\n"]
block3["print(#quot;Somewhere else#quot;)\n"]
block4["match point:
case Point(x=0, y=0):
print(#quot;Origin#quot;)
case Point(x=0, y=y):
print(f#quot;Y={y}#quot;)
case Point(x=x, y=0):
print(f#quot;X={x}#quot;)
case Point():
print(#quot;Somewhere else#quot;)
case _:
print(#quot;Not a point#quot;)\n"]
block5["print(f#quot;X={x}#quot;)\n"]
block6["match point:
case Point(x=0, y=0):
print(#quot;Origin#quot;)
case Point(x=0, y=y):
print(f#quot;Y={y}#quot;)
case Point(x=x, y=0):
print(f#quot;X={x}#quot;)
case Point():
print(#quot;Somewhere else#quot;)
case _:
print(#quot;Not a point#quot;)\n"]
block7["print(f#quot;Y={y}#quot;)\n"]
block8["match point:
case Point(x=0, y=0):
print(#quot;Origin#quot;)
case Point(x=0, y=y):
print(f#quot;Y={y}#quot;)
case Point(x=x, y=0):
print(f#quot;X={x}#quot;)
case Point():
print(#quot;Somewhere else#quot;)
case _:
print(#quot;Not a point#quot;)\n"]
block9["print(#quot;Origin#quot;)\n"]
block10["match point:
case Point(x=0, y=0):
print(#quot;Origin#quot;)
case Point(x=0, y=y):
print(f#quot;Y={y}#quot;)
case Point(x=x, y=0):
print(f#quot;X={x}#quot;)
case Point():
print(#quot;Somewhere else#quot;)
case _:
print(#quot;Not a point#quot;)\n"]
block11["class Point:
x: int
y: int\n"]
start --> block11
block11 --> block10
block10 -- "case Point(x=0, y=0)" --> block9
block10 -- "else" --> block8
block9 --> block0
block8 -- "case Point(x=0, y=y)" --> block7
block8 -- "else" --> block6
block7 --> block0
block6 -- "case Point(x=x, y=0)" --> block5
block6 -- "else" --> block4
block5 --> block0
block4 -- "case Point()" --> block3
block4 -- "else" --> block2
block3 --> block0
block2 --> block1
block1 --> block0
block0 --> return
```
## Function 11
### Source
```python
def func(points):
match points:
case []:
print("No points")
case [Point(0, 0)]:
print("The origin")
case [Point(x, y)]:
print(f"Single point {x}, {y}")
case [Point(0, y1), Point(0, y2)]:
print(f"Two on the Y axis at {y1}, {y2}")
case _:
print("Something else")
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0[["`*(empty)*`"]]
block1["print(#quot;Something else#quot;)\n"]
block2["match points:
case []:
print(#quot;No points#quot;)
case [Point(0, 0)]:
print(#quot;The origin#quot;)
case [Point(x, y)]:
print(f#quot;Single point {x}, {y}#quot;)
case [Point(0, y1), Point(0, y2)]:
print(f#quot;Two on the Y axis at {y1}, {y2}#quot;)
case _:
print(#quot;Something else#quot;)\n"]
block3["print(f#quot;Two on the Y axis at {y1}, {y2}#quot;)\n"]
block4["match points:
case []:
print(#quot;No points#quot;)
case [Point(0, 0)]:
print(#quot;The origin#quot;)
case [Point(x, y)]:
print(f#quot;Single point {x}, {y}#quot;)
case [Point(0, y1), Point(0, y2)]:
print(f#quot;Two on the Y axis at {y1}, {y2}#quot;)
case _:
print(#quot;Something else#quot;)\n"]
block5["print(f#quot;Single point {x}, {y}#quot;)\n"]
block6["match points:
case []:
print(#quot;No points#quot;)
case [Point(0, 0)]:
print(#quot;The origin#quot;)
case [Point(x, y)]:
print(f#quot;Single point {x}, {y}#quot;)
case [Point(0, y1), Point(0, y2)]:
print(f#quot;Two on the Y axis at {y1}, {y2}#quot;)
case _:
print(#quot;Something else#quot;)\n"]
block7["print(#quot;The origin#quot;)\n"]
block8["match points:
case []:
print(#quot;No points#quot;)
case [Point(0, 0)]:
print(#quot;The origin#quot;)
case [Point(x, y)]:
print(f#quot;Single point {x}, {y}#quot;)
case [Point(0, y1), Point(0, y2)]:
print(f#quot;Two on the Y axis at {y1}, {y2}#quot;)
case _:
print(#quot;Something else#quot;)\n"]
block9["print(#quot;No points#quot;)\n"]
block10["match points:
case []:
print(#quot;No points#quot;)
case [Point(0, 0)]:
print(#quot;The origin#quot;)
case [Point(x, y)]:
print(f#quot;Single point {x}, {y}#quot;)
case [Point(0, y1), Point(0, y2)]:
print(f#quot;Two on the Y axis at {y1}, {y2}#quot;)
case _:
print(#quot;Something else#quot;)\n"]
start --> block10
block10 -- "case []" --> block9
block10 -- "else" --> block8
block9 --> block0
block8 -- "case [Point(0, 0)]" --> block7
block8 -- "else" --> block6
block7 --> block0
block6 -- "case [Point(x, y)]" --> block5
block6 -- "else" --> block4
block5 --> block0
block4 -- "case [Point(0, y1), Point(0, y2)]" --> block3
block4 -- "else" --> block2
block3 --> block0
block2 --> block1
block1 --> block0
block0 --> return
```
## Function 12
### Source
```python
def func(point):
match point:
case Point(x, y) if x == y:
print(f"Y=X at {x}")
case Point(x, y):
print(f"Not on the diagonal")
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0[["`*(empty)*`"]]
block1["print(f#quot;Not on the diagonal#quot;)\n"]
block2["match point:
case Point(x, y) if x == y:
print(f#quot;Y=X at {x}#quot;)
case Point(x, y):
print(f#quot;Not on the diagonal#quot;)\n"]
block3["print(f#quot;Y=X at {x}#quot;)\n"]
block4["match point:
case Point(x, y) if x == y:
print(f#quot;Y=X at {x}#quot;)
case Point(x, y):
print(f#quot;Not on the diagonal#quot;)\n"]
start --> block4
block4 -- "case Point(x, y) if x == y" --> block3
block4 -- "else" --> block2
block3 --> block0
block2 -- "case Point(x, y)" --> block1
block2 -- "else" --> block0
block1 --> block0
block0 --> return
```
## Function 13
### Source
```python
def func():
from enum import Enum
class Color(Enum):
RED = 'red'
GREEN = 'green'
BLUE = 'blue'
color = Color(input("Enter your choice of 'red', 'blue' or 'green': "))
match color:
case Color.RED:
print("I see red!")
case Color.GREEN:
print("Grass is green")
case Color.BLUE:
print("I'm feeling the blues :(")
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0[["`*(empty)*`"]]
block1["print(#quot;I'm feeling the blues :(#quot;)\n"]
block2["match color:
case Color.RED:
print(#quot;I see red!#quot;)
case Color.GREEN:
print(#quot;Grass is green#quot;)
case Color.BLUE:
print(#quot;I'm feeling the blues :(#quot;)\n"]
block3["print(#quot;Grass is green#quot;)\n"]
block4["match color:
case Color.RED:
print(#quot;I see red!#quot;)
case Color.GREEN:
print(#quot;Grass is green#quot;)
case Color.BLUE:
print(#quot;I'm feeling the blues :(#quot;)\n"]
block5["print(#quot;I see red!#quot;)\n"]
block6["match color:
case Color.RED:
print(#quot;I see red!#quot;)
case Color.GREEN:
print(#quot;Grass is green#quot;)
case Color.BLUE:
print(#quot;I'm feeling the blues :(#quot;)\n"]
block7["from enum import Enum\nclass Color(Enum):
RED = 'red'
GREEN = 'green'
BLUE = 'blue'\ncolor = Color(input(#quot;Enter your choice of 'red', 'blue' or 'green': #quot;))\n"]
start --> block7
block7 --> block6
block6 -- "case Color.RED" --> block5
block6 -- "else" --> block4
block5 --> block0
block4 -- "case Color.GREEN" --> block3
block4 -- "else" --> block2
block3 --> block0
block2 -- "case Color.BLUE" --> block1
block2 -- "else" --> block0
block1 --> block0
block0 --> return
```
## Function 14
### Source
```python
def func(point):
match point:
case (0, 0):
print("Origin")
case foo:
raise ValueError("oops")
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0[["`*(empty)*`"]]
block1[["Exception raised"]]
block2["raise ValueError(#quot;oops#quot;)\n"]
block3["match point:
case (0, 0):
print(#quot;Origin#quot;)
case foo:
raise ValueError(#quot;oops#quot;)\n"]
block4["print(#quot;Origin#quot;)\n"]
block5["match point:
case (0, 0):
print(#quot;Origin#quot;)
case foo:
raise ValueError(#quot;oops#quot;)\n"]
start --> block5
block5 -- "case (0, 0)" --> block4
block5 -- "else" --> block3
block4 --> block0
block3 --> block2
block2 --> block1
block1 --> return
block0 --> return
```

View file

@ -0,0 +1,43 @@
---
source: crates/ruff_linter/src/rules/pylint/rules/unreachable.rs
description: "This is a Mermaid graph. You can use https://mermaid.live to visualize it as a diagram."
---
## Function 0
### Source
```python
def func():
raise Exception
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0[["Exception raised"]]
block1["raise Exception\n"]
start --> block1
block1 --> block0
block0 --> return
```
## Function 1
### Source
```python
def func():
raise "a glass!"
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0[["Exception raised"]]
block1["raise #quot;a glass!#quot;\n"]
start --> block1
block1 --> block0
block0 --> return
```

View file

@ -0,0 +1,188 @@
---
source: crates/ruff_linter/src/rules/pylint/rules/unreachable.rs
description: "This is a Mermaid graph. You can use https://mermaid.live to visualize it as a diagram."
---
## Function 0
### Source
```python
def func():
pass
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0["pass\n"]
start --> block0
block0 --> return
```
## Function 1
### Source
```python
def func():
pass
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0["pass\n"]
start --> block0
block0 --> return
```
## Function 2
### Source
```python
def func():
return
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0["return\n"]
start --> block0
block0 --> return
```
## Function 3
### Source
```python
def func():
return 1
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0["return 1\n"]
start --> block0
block0 --> return
```
## Function 4
### Source
```python
def func():
return 1
return "unreachable"
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0["return #quot;unreachable#quot;\n"]
block1["return 1\n"]
start --> block1
block1 --> return
block0 --> return
```
## Function 5
### Source
```python
def func():
i = 0
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0["i = 0\n"]
start --> block0
block0 --> return
```
## Function 6
### Source
```python
def func():
i = 0
i += 2
return i
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0["i = 0\ni += 2\nreturn i\n"]
start --> block0
block0 --> return
```
## Function 7
### Source
```python
def func():
with x:
i = 0
i = 1
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0["i = 1\n"]
block1["i = 0\n"]
block2["with x:
i = 0\n"]
start --> block2
block2 -- "Exception raised" --> block0
block2 -- "else" --> block1
block1 --> block0
block0 --> return
```
## Function 8
### Source
```python
def func():
with x:
i = 0
return 1
i = 1
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0["i = 1\n"]
block1["i = 0\nreturn 1\n"]
block2["with x:
i = 0
return 1\n"]
start --> block2
block2 -- "Exception raised" --> block0
block2 -- "else" --> block1
block1 --> return
block0 --> return
```

View file

@ -0,0 +1,710 @@
---
source: crates/ruff_linter/src/rules/pylint/rules/unreachable.rs
description: "This is a Mermaid graph. You can use https://mermaid.live to visualize it as a diagram."
---
## Function 0
### Source
```python
def func():
try:
print("try")
except Exception:
print("Exception")
except OtherException as e:
print("OtherException")
else:
print("else")
finally:
print("finally")
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0[["`*(empty)*`"]]
block1["print(#quot;finally#quot;)\n"]
block2["print(#quot;else#quot;)\n"]
block3["print(#quot;try#quot;)\n"]
block4[["Exception raised"]]
block5["print(#quot;OtherException#quot;)\n"]
block6["try:
print(#quot;try#quot;)
except Exception:
print(#quot;Exception#quot;)
except OtherException as e:
print(#quot;OtherException#quot;)
else:
print(#quot;else#quot;)
finally:
print(#quot;finally#quot;)\n"]
block7["print(#quot;Exception#quot;)\n"]
block8["try:
print(#quot;try#quot;)
except Exception:
print(#quot;Exception#quot;)
except OtherException as e:
print(#quot;OtherException#quot;)
else:
print(#quot;else#quot;)
finally:
print(#quot;finally#quot;)\n"]
block9["try:
print(#quot;try#quot;)
except Exception:
print(#quot;Exception#quot;)
except OtherException as e:
print(#quot;OtherException#quot;)
else:
print(#quot;else#quot;)
finally:
print(#quot;finally#quot;)\n"]
start --> block9
block9 -- "Exception raised" --> block8
block9 -- "else" --> block3
block8 -- "Exception" --> block7
block8 -- "else" --> block6
block7 --> block1
block6 -- "OtherException" --> block5
block6 -- "else" --> block4
block5 --> block1
block4 --> block1
block3 --> block2
block2 --> block1
block1 --> block0
block0 --> return
```
## Function 1
### Source
```python
def func():
try:
print("try")
except:
print("Exception")
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0[["`*(empty)*`"]]
block1["print(#quot;try#quot;)\n"]
block2[["Exception raised"]]
block3["print(#quot;Exception#quot;)\n"]
block4["try:
print(#quot;try#quot;)
except:
print(#quot;Exception#quot;)\n"]
start --> block4
block4 -- "Exception raised" --> block3
block4 -- "else" --> block1
block3 --> block0
block2 --> return
block1 --> block0
block0 --> return
```
## Function 2
### Source
```python
def func():
try:
print("try")
except:
print("Exception")
except OtherException as e:
print("OtherException")
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0[["`*(empty)*`"]]
block1["print(#quot;try#quot;)\n"]
block2[["Exception raised"]]
block3["print(#quot;OtherException#quot;)\n"]
block4["try:
print(#quot;try#quot;)
except:
print(#quot;Exception#quot;)
except OtherException as e:
print(#quot;OtherException#quot;)\n"]
block5["print(#quot;Exception#quot;)\n"]
block6["try:
print(#quot;try#quot;)
except:
print(#quot;Exception#quot;)
except OtherException as e:
print(#quot;OtherException#quot;)\n"]
start --> block6
block6 -- "Exception raised" --> block5
block6 -- "else" --> block1
block5 --> block0
block4 -- "OtherException" --> block3
block4 -- "else" --> block2
block3 --> block0
block2 --> return
block1 --> block0
block0 --> return
```
## Function 3
### Source
```python
def func():
try:
print("try")
except Exception:
print("Exception")
except OtherException as e:
print("OtherException")
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0[["`*(empty)*`"]]
block1["print(#quot;try#quot;)\n"]
block2[["Exception raised"]]
block3["print(#quot;OtherException#quot;)\n"]
block4["try:
print(#quot;try#quot;)
except Exception:
print(#quot;Exception#quot;)
except OtherException as e:
print(#quot;OtherException#quot;)\n"]
block5["print(#quot;Exception#quot;)\n"]
block6["try:
print(#quot;try#quot;)
except Exception:
print(#quot;Exception#quot;)
except OtherException as e:
print(#quot;OtherException#quot;)\n"]
block7["try:
print(#quot;try#quot;)
except Exception:
print(#quot;Exception#quot;)
except OtherException as e:
print(#quot;OtherException#quot;)\n"]
start --> block7
block7 -- "Exception raised" --> block6
block7 -- "else" --> block1
block6 -- "Exception" --> block5
block6 -- "else" --> block4
block5 --> block0
block4 -- "OtherException" --> block3
block4 -- "else" --> block2
block3 --> block0
block2 --> return
block1 --> block0
block0 --> return
```
## Function 4
### Source
```python
def func():
try:
print("try")
except Exception:
print("Exception")
except OtherException as e:
print("OtherException")
else:
print("else")
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0[["`*(empty)*`"]]
block1["print(#quot;else#quot;)\n"]
block2["print(#quot;try#quot;)\n"]
block3[["Exception raised"]]
block4["print(#quot;OtherException#quot;)\n"]
block5["try:
print(#quot;try#quot;)
except Exception:
print(#quot;Exception#quot;)
except OtherException as e:
print(#quot;OtherException#quot;)
else:
print(#quot;else#quot;)\n"]
block6["print(#quot;Exception#quot;)\n"]
block7["try:
print(#quot;try#quot;)
except Exception:
print(#quot;Exception#quot;)
except OtherException as e:
print(#quot;OtherException#quot;)
else:
print(#quot;else#quot;)\n"]
block8["try:
print(#quot;try#quot;)
except Exception:
print(#quot;Exception#quot;)
except OtherException as e:
print(#quot;OtherException#quot;)
else:
print(#quot;else#quot;)\n"]
start --> block8
block8 -- "Exception raised" --> block7
block8 -- "else" --> block2
block7 -- "Exception" --> block6
block7 -- "else" --> block5
block6 --> block0
block5 -- "OtherException" --> block4
block5 -- "else" --> block3
block4 --> block0
block3 --> return
block2 --> block1
block1 --> block0
block0 --> return
```
## Function 5
### Source
```python
def func():
try:
print("try")
finally:
print("finally")
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0[["`*(empty)*`"]]
block1["print(#quot;finally#quot;)\n"]
block2["print(#quot;try#quot;)\n"]
block3[["Exception raised"]]
block4["try:
print(#quot;try#quot;)
finally:
print(#quot;finally#quot;)\n"]
start --> block4
block4 -- "Exception raised" --> block3
block4 -- "else" --> block2
block3 --> block1
block2 --> block1
block1 --> block0
block0 --> return
```
## Function 6
### Source
```python
def func():
try:
return 0
except:
return 1
finally:
return 2
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0[["`*(empty)*`"]]
block1["return 2\n"]
block2["return 0\n"]
block3[["Exception raised"]]
block4["return 1\n"]
block5["try:
return 0
except:
return 1
finally:
return 2\n"]
start --> block5
block5 -- "Exception raised" --> block4
block5 -- "else" --> block2
block4 --> block1
block3 --> block1
block2 --> block1
block1 --> return
block0 --> return
```
## Function 7
### Source
```python
def func():
try:
raise Exception()
except:
print("reached")
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0[["`*(empty)*`"]]
block1[["Exception raised"]]
block2["raise Exception()\n"]
block3[["Exception raised"]]
block4["print(#quot;reached#quot;)\n"]
block5["try:
raise Exception()
except:
print(#quot;reached#quot;)\n"]
start --> block5
block5 -- "Exception raised" --> block4
block5 -- "else" --> block2
block4 --> block0
block3 --> return
block2 --> block4
block1 --> return
block0 --> return
```
## Function 8
### Source
```python
def func():
try:
assert False
print("unreachable")
except:
print("reached")
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0[["`*(empty)*`"]]
block1["print(#quot;unreachable#quot;)\n"]
block2[["Exception raised"]]
block3["assert False\n"]
block4[["Exception raised"]]
block5["print(#quot;reached#quot;)\n"]
block6["try:
assert False
print(#quot;unreachable#quot;)
except:
print(#quot;reached#quot;)\n"]
start --> block6
block6 -- "Exception raised" --> block5
block6 -- "else" --> block3
block5 --> block0
block4 --> return
block3 -- "False" --> block1
block3 -- "else" --> block5
block2 --> return
block1 --> block0
block0 --> return
```
## Function 9
### Source
```python
def func():
try:
raise Exception()
finally:
print('reached')
return 2
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0[["`*(empty)*`"]]
block1["print('reached')\nreturn 2\n"]
block2[["Exception raised"]]
block3["raise Exception()\n"]
block4[["Exception raised"]]
block5["try:
raise Exception()
finally:
print('reached')
return 2\n"]
start --> block5
block5 -- "Exception raised" --> block4
block5 -- "else" --> block3
block4 --> block1
block3 --> block1
block2 --> return
block1 --> return
block0 --> return
```
## Function 10
### Source
```python
def func():
try:
assert False
print("unreachable")
finally:
print("reached")
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0[["`*(empty)*`"]]
block1["print(#quot;reached#quot;)\n"]
block2["print(#quot;unreachable#quot;)\n"]
block3[["Exception raised"]]
block4["assert False\n"]
block5[["Exception raised"]]
block6["try:
assert False
print(#quot;unreachable#quot;)
finally:
print(#quot;reached#quot;)\n"]
start --> block6
block6 -- "Exception raised" --> block5
block6 -- "else" --> block4
block5 --> block1
block4 -- "False" --> block2
block4 -- "else" --> block1
block3 --> return
block2 --> block1
block1 --> block0
block0 --> return
```
## Function 11
### Source
```python
def func():
try:
if catalog is not None:
try:
x = 0
except PySparkParseException:
x = 1
try:
x = 2
except PySparkParseException:
x = 3
x = 8
finally:
if catalog is not None:
try:
x = 4
except PySparkParseException:
x = 5
try:
x = 6
except PySparkParseException:
x = 7
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0[["`*(empty)*`"]]
block1["x = 6\n"]
block2[["Exception raised"]]
block3["x = 7\n"]
block4["try:
x = 6
except PySparkParseException:
x = 7\n"]
block5["try:
x = 6
except PySparkParseException:
x = 7\n"]
block6["x = 4\n"]
block7[["Exception raised"]]
block8["x = 5\n"]
block9["try:
x = 4
except PySparkParseException:
x = 5\n"]
block10["try:
x = 4
except PySparkParseException:
x = 5\n"]
block11["if catalog is not None:
try:
x = 4
except PySparkParseException:
x = 5\n"]
block12["x = 8\n"]
block13["x = 2\n"]
block14[["Exception raised"]]
block15["x = 3\n"]
block16["try:
x = 2
except PySparkParseException:
x = 3\n"]
block17["try:
x = 2
except PySparkParseException:
x = 3\n"]
block18["x = 0\n"]
block19[["Exception raised"]]
block20["x = 1\n"]
block21["try:
x = 0
except PySparkParseException:
x = 1\n"]
block22["try:
x = 0
except PySparkParseException:
x = 1\n"]
block23["if catalog is not None:
try:
x = 0
except PySparkParseException:
x = 1\n"]
block24[["Exception raised"]]
block25["try:
if catalog is not None:
try:
x = 0
except PySparkParseException:
x = 1
try:
x = 2
except PySparkParseException:
x = 3
x = 8
finally:
if catalog is not None:
try:
x = 4
except PySparkParseException:
x = 5
try:
x = 6
except PySparkParseException:
x = 7\n"]
start --> block25
block25 -- "Exception raised" --> block24
block25 -- "else" --> block23
block24 --> block11
block23 -- "catalog is not None" --> block22
block23 -- "else" --> block17
block22 -- "Exception raised" --> block21
block22 -- "else" --> block18
block21 -- "PySparkParseException" --> block20
block21 -- "else" --> block19
block20 --> block17
block19 --> block11
block18 --> block17
block17 -- "Exception raised" --> block16
block17 -- "else" --> block13
block16 -- "PySparkParseException" --> block15
block16 -- "else" --> block14
block15 --> block12
block14 --> block11
block13 --> block12
block12 --> block11
block11 -- "catalog is not None" --> block10
block11 -- "else" --> block5
block10 -- "Exception raised" --> block9
block10 -- "else" --> block6
block9 -- "PySparkParseException" --> block8
block9 -- "else" --> block7
block8 --> block5
block7 --> return
block6 --> block5
block5 -- "Exception raised" --> block4
block5 -- "else" --> block1
block4 -- "PySparkParseException" --> block3
block4 -- "else" --> block2
block3 --> block0
block2 --> return
block1 --> block0
block0 --> return
```
## Function 12
### Source
```python
def func():
try:
assert False
except ex:
raise ex
finally:
raise Exception("other")
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0[["`*(empty)*`"]]
block1[["Exception raised"]]
block2["raise Exception(#quot;other#quot;)\n"]
block3[["Exception raised"]]
block4["assert False\n"]
block5[["Exception raised"]]
block6[["Exception raised"]]
block7["raise ex\n"]
block8["try:
assert False
except ex:
raise ex
finally:
raise Exception(#quot;other#quot;)\n"]
block9["try:
assert False
except ex:
raise ex
finally:
raise Exception(#quot;other#quot;)\n"]
start --> block9
block9 -- "Exception raised" --> block8
block9 -- "else" --> block4
block8 -- "ex" --> block7
block8 -- "else" --> block5
block7 --> block2
block6 --> return
block5 --> block2
block4 -- "False" --> block2
block4 -- "else" --> block8
block3 --> return
block2 --> block1
block1 --> return
block0 --> return
```

View file

@ -0,0 +1,779 @@
---
source: crates/ruff_linter/src/rules/pylint/rules/unreachable.rs
description: "This is a Mermaid graph. You can use https://mermaid.live to visualize it as a diagram."
---
## Function 0
### Source
```python
def func():
while False:
return "unreachable"
return 1
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0["return 1\n"]
block1[["Loop continue"]]
block2["return #quot;unreachable#quot;\n"]
block3["while False:
return #quot;unreachable#quot;\n"]
start --> block3
block3 -- "False" --> block2
block3 -- "else" --> block0
block2 --> return
block1 --> block3
block0 --> return
```
## Function 1
### Source
```python
def func():
while False:
return "unreachable"
else:
return 1
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0[["`*(empty)*`"]]
block1["return 1\n"]
block2[["Loop continue"]]
block3["return #quot;unreachable#quot;\n"]
block4["while False:
return #quot;unreachable#quot;
else:
return 1\n"]
start --> block4
block4 -- "False" --> block3
block4 -- "else" --> block1
block3 --> return
block2 --> block4
block1 --> return
block0 --> return
```
## Function 2
### Source
```python
def func():
while False:
return "unreachable"
else:
return 1
return "also unreachable"
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0["return #quot;also unreachable#quot;\n"]
block1["return 1\n"]
block2[["Loop continue"]]
block3["return #quot;unreachable#quot;\n"]
block4["while False:
return #quot;unreachable#quot;
else:
return 1\n"]
start --> block4
block4 -- "False" --> block3
block4 -- "else" --> block1
block3 --> return
block2 --> block4
block1 --> return
block0 --> return
```
## Function 3
### Source
```python
def func():
while True:
return 1
return "unreachable"
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0["return #quot;unreachable#quot;\n"]
block1[["Loop continue"]]
block2["return 1\n"]
block3["while True:
return 1\n"]
start --> block3
block3 -- "True" --> block2
block3 -- "else" --> block0
block2 --> return
block1 --> block3
block0 --> return
```
## Function 4
### Source
```python
def func():
while True:
return 1
else:
return "unreachable"
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0[["`*(empty)*`"]]
block1["return #quot;unreachable#quot;\n"]
block2[["Loop continue"]]
block3["return 1\n"]
block4["while True:
return 1
else:
return #quot;unreachable#quot;\n"]
start --> block4
block4 -- "True" --> block3
block4 -- "else" --> block1
block3 --> return
block2 --> block4
block1 --> return
block0 --> return
```
## Function 5
### Source
```python
def func():
while True:
return 1
else:
return "unreachable"
return "also unreachable"
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0["return #quot;also unreachable#quot;\n"]
block1["return #quot;unreachable#quot;\n"]
block2[["Loop continue"]]
block3["return 1\n"]
block4["while True:
return 1
else:
return #quot;unreachable#quot;\n"]
start --> block4
block4 -- "True" --> block3
block4 -- "else" --> block1
block3 --> return
block2 --> block4
block1 --> return
block0 --> return
```
## Function 6
### Source
```python
def func():
i = 0
while False:
i += 1
return i
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0["return i\n"]
block1[["Loop continue"]]
block2["i += 1\n"]
block3["i = 0\nwhile False:
i += 1\n"]
start --> block3
block3 -- "False" --> block2
block3 -- "else" --> block0
block2 --> block1
block1 --> block3
block0 --> return
```
## Function 7
### Source
```python
def func():
i = 0
while True:
i += 1
return i
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0["return i\n"]
block1[["Loop continue"]]
block2["i += 1\n"]
block3["i = 0\nwhile True:
i += 1\n"]
start --> block3
block3 -- "True" --> block2
block3 -- "else" --> block0
block2 --> block1
block1 --> block3
block0 --> return
```
## Function 8
### Source
```python
def func():
while True:
pass
return 1
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0["return 1\n"]
block1[["Loop continue"]]
block2["pass\n"]
block3["while True:
pass\n"]
start --> block3
block3 -- "True" --> block2
block3 -- "else" --> block0
block2 --> block1
block1 --> block3
block0 --> return
```
## Function 9
### Source
```python
def func():
i = 0
while True:
if True:
print("ok")
i += 1
return i
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0["return i\n"]
block1[["Loop continue"]]
block2["i += 1\n"]
block3["print(#quot;ok#quot;)\n"]
block4["if True:
print(#quot;ok#quot;)\n"]
block5["i = 0\nwhile True:
if True:
print(#quot;ok#quot;)
i += 1\n"]
start --> block5
block5 -- "True" --> block4
block5 -- "else" --> block0
block4 -- "True" --> block3
block4 -- "else" --> block2
block3 --> block2
block2 --> block1
block1 --> block5
block0 --> return
```
## Function 10
### Source
```python
def func():
i = 0
while True:
if False:
print("ok")
i += 1
return i
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0["return i\n"]
block1[["Loop continue"]]
block2["i += 1\n"]
block3["print(#quot;ok#quot;)\n"]
block4["if False:
print(#quot;ok#quot;)\n"]
block5["i = 0\nwhile True:
if False:
print(#quot;ok#quot;)
i += 1\n"]
start --> block5
block5 -- "True" --> block4
block5 -- "else" --> block0
block4 -- "False" --> block3
block4 -- "else" --> block2
block3 --> block2
block2 --> block1
block1 --> block5
block0 --> return
```
## Function 11
### Source
```python
def func():
while True:
if True:
return 1
return 0
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0["return 0\n"]
block1[["Loop continue"]]
block2["return 1\n"]
block3["if True:
return 1\n"]
block4["while True:
if True:
return 1\n"]
start --> block4
block4 -- "True" --> block3
block4 -- "else" --> block0
block3 -- "True" --> block2
block3 -- "else" --> block1
block2 --> return
block1 --> block4
block0 --> return
```
## Function 12
### Source
```python
def func():
while True:
continue
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0[["`*(empty)*`"]]
block1[["Loop continue"]]
block2["continue\n"]
block3["while True:
continue\n"]
start --> block3
block3 -- "True" --> block2
block3 -- "else" --> block0
block2 --> block3
block1 --> block3
block0 --> return
```
## Function 13
### Source
```python
def func():
while False:
continue
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0[["`*(empty)*`"]]
block1[["Loop continue"]]
block2["continue\n"]
block3["while False:
continue\n"]
start --> block3
block3 -- "False" --> block2
block3 -- "else" --> block0
block2 --> block3
block1 --> block3
block0 --> return
```
## Function 14
### Source
```python
def func():
while True:
break
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0[["`*(empty)*`"]]
block1[["Loop continue"]]
block2["break\n"]
block3["while True:
break\n"]
start --> block3
block3 -- "True" --> block2
block3 -- "else" --> block0
block2 --> return
block1 --> block3
block0 --> return
```
## Function 15
### Source
```python
def func():
while False:
break
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0[["`*(empty)*`"]]
block1[["Loop continue"]]
block2["break\n"]
block3["while False:
break\n"]
start --> block3
block3 -- "False" --> block2
block3 -- "else" --> block0
block2 --> return
block1 --> block3
block0 --> return
```
## Function 16
### Source
```python
def func():
while True:
if True:
continue
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0[["`*(empty)*`"]]
block1[["Loop continue"]]
block2["continue\n"]
block3["if True:
continue\n"]
block4["while True:
if True:
continue\n"]
start --> block4
block4 -- "True" --> block3
block4 -- "else" --> block0
block3 -- "True" --> block2
block3 -- "else" --> block1
block2 --> block4
block1 --> block4
block0 --> return
```
## Function 17
### Source
```python
def func():
while True:
if True:
break
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0[["`*(empty)*`"]]
block1[["Loop continue"]]
block2["break\n"]
block3["if True:
break\n"]
block4["while True:
if True:
break\n"]
start --> block4
block4 -- "True" --> block3
block4 -- "else" --> block0
block3 -- "True" --> block2
block3 -- "else" --> block1
block2 --> return
block1 --> block4
block0 --> return
```
## Function 18
### Source
```python
def func():
while True:
x = 0
x = 1
break
x = 2
x = 3
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0["x = 3\n"]
block1[["Loop continue"]]
block2["x = 2\n"]
block3["x = 0\nx = 1\nbreak\n"]
block4["while True:
x = 0
x = 1
break
x = 2\n"]
start --> block4
block4 -- "True" --> block3
block4 -- "else" --> block0
block3 --> block0
block2 --> block1
block1 --> block4
block0 --> return
```
## Function 19
### Source
```python
def func():
while True:
x = 0
x = 1
continue
x = 2
x = 3
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0["x = 3\n"]
block1[["Loop continue"]]
block2["x = 2\n"]
block3["x = 0\nx = 1\ncontinue\n"]
block4["while True:
x = 0
x = 1
continue
x = 2\n"]
start --> block4
block4 -- "True" --> block3
block4 -- "else" --> block0
block3 --> block4
block2 --> block1
block1 --> block4
block0 --> return
```
## Function 20
### Source
```python
def func():
while True:
x = 0
x = 1
return
x = 2
x = 3
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0["x = 3\n"]
block1[["Loop continue"]]
block2["x = 2\n"]
block3["x = 0\nx = 1\nreturn\n"]
block4["while True:
x = 0
x = 1
return
x = 2\n"]
start --> block4
block4 -- "True" --> block3
block4 -- "else" --> block0
block3 --> return
block2 --> block1
block1 --> block4
block0 --> return
```
## Function 21
### Source
```python
def func():
while True:
x = 0
x = 1
raise Exception
x = 2
x = 3
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0["x = 3\n"]
block1[["Loop continue"]]
block2["x = 2\n"]
block3[["Exception raised"]]
block4["x = 0\nx = 1\nraise Exception\n"]
block5["while True:
x = 0
x = 1
raise Exception
x = 2\n"]
start --> block5
block5 -- "True" --> block4
block5 -- "else" --> block0
block4 --> block3
block3 --> return
block2 --> block1
block1 --> block5
block0 --> return
```
## Function 22
### Source
```python
def bokeh2(self, host: str = DEFAULT_HOST, port: int = DEFAULT_PORT) -> None:
self.stop_serving = False
while True:
try:
self.server = HTTPServer((host, port), HtmlOnlyHandler)
self.host = host
self.port = port
break
except OSError:
log.debug(f"port {port} is in use, trying to next one")
port += 1
self.thread = threading.Thread(target=self._run_web_server)
```
### Control Flow Graph
```mermaid
flowchart TD
start(("Start"))
return(("End"))
block0["self.thread = threading.Thread(target=self._run_web_server)\n"]
block1[["Loop continue"]]
block2["self.server = HTTPServer((host, port), HtmlOnlyHandler)\nself.host = host\nself.port = port\nbreak\n"]
block3[["Exception raised"]]
block4["log.debug(f#quot;port {port} is in use, trying to next one#quot;)\nport += 1\n"]
block5["try:
self.server = HTTPServer((host, port), HtmlOnlyHandler)
self.host = host
self.port = port
break
except OSError:
log.debug(f#quot;port {port} is in use, trying to next one#quot;)
port += 1\n"]
block6["try:
self.server = HTTPServer((host, port), HtmlOnlyHandler)
self.host = host
self.port = port
break
except OSError:
log.debug(f#quot;port {port} is in use, trying to next one#quot;)
port += 1\n"]
block7["self.stop_serving = False\nwhile True:
try:
self.server = HTTPServer((host, port), HtmlOnlyHandler)
self.host = host
self.port = port
break
except OSError:
log.debug(f#quot;port {port} is in use, trying to next one#quot;)
port += 1\n"]
start --> block7
block7 -- "True" --> block6
block7 -- "else" --> block0
block6 -- "Exception raised" --> block5
block6 -- "else" --> block2
block5 -- "OSError" --> block4
block5 -- "else" --> block3
block4 --> block1
block3 --> return
block2 --> block0
block1 --> block7
block0 --> return
```

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,270 @@
---
source: crates/ruff_linter/src/rules/pylint/mod.rs
---
unreachable.py:3:5: PLW0101 Unreachable code in `after_return`
|
1 | def after_return():
2 | return "reachable"
3 | return "unreachable"
| ^^^^^^^^^^^^^^^^^^^^ PLW0101
4 |
5 | async def also_works_on_async_functions():
|
unreachable.py:7:5: PLW0101 Unreachable code in `also_works_on_async_functions`
|
5 | async def also_works_on_async_functions():
6 | return "reachable"
7 | return "unreachable"
| ^^^^^^^^^^^^^^^^^^^^ PLW0101
8 |
9 | def if_always_true():
|
unreachable.py:12:5: PLW0101 Unreachable code in `if_always_true`
|
10 | if True:
11 | return "reachable"
12 | return "unreachable"
| ^^^^^^^^^^^^^^^^^^^^ PLW0101
13 |
14 | def if_always_false():
|
unreachable.py:16:9: PLW0101 Unreachable code in `if_always_false`
|
14 | def if_always_false():
15 | if False:
16 | return "unreachable"
| ^^^^^^^^^^^^^^^^^^^^ PLW0101
17 | return "reachable"
|
unreachable.py:21:9: PLW0101 Unreachable code in `if_elif_always_false`
|
19 | def if_elif_always_false():
20 | if False:
21 | return "unreachable"
| _________^
22 | | elif False:
23 | | return "also unreachable"
| |_________________________________^ PLW0101
24 | return "reachable"
|
unreachable.py:28:9: PLW0101 Unreachable code in `if_elif_always_true`
|
26 | def if_elif_always_true():
27 | if False:
28 | return "unreachable"
| ^^^^^^^^^^^^^^^^^^^^ PLW0101
29 | elif True:
30 | return "reachable"
|
unreachable.py:31:5: PLW0101 Unreachable code in `if_elif_always_true`
|
29 | elif True:
30 | return "reachable"
31 | return "also unreachable"
| ^^^^^^^^^^^^^^^^^^^^^^^^^ PLW0101
32 |
33 | def ends_with_if():
|
unreachable.py:35:9: PLW0101 Unreachable code in `ends_with_if`
|
33 | def ends_with_if():
34 | if False:
35 | return "unreachable"
| ^^^^^^^^^^^^^^^^^^^^ PLW0101
36 | else:
37 | return "reachable"
|
unreachable.py:42:5: PLW0101 Unreachable code in `infinite_loop`
|
40 | while True:
41 | continue
42 | return "unreachable"
| ^^^^^^^^^^^^^^^^^^^^ PLW0101
43 |
44 | ''' TODO: we could determine these, but we don't yet.
|
unreachable.py:75:5: PLW0101 Unreachable code in `match_wildcard`
|
73 | case _:
74 | return "reachable"
75 | return "unreachable"
| ^^^^^^^^^^^^^^^^^^^^ PLW0101
76 |
77 | def match_case_and_wildcard(status):
|
unreachable.py:83:5: PLW0101 Unreachable code in `match_case_and_wildcard`
|
81 | case _:
82 | return "reachable"
83 | return "unreachable"
| ^^^^^^^^^^^^^^^^^^^^ PLW0101
84 |
85 | def raise_exception():
|
unreachable.py:87:5: PLW0101 Unreachable code in `raise_exception`
|
85 | def raise_exception():
86 | raise Exception
87 | return "unreachable"
| ^^^^^^^^^^^^^^^^^^^^ PLW0101
88 |
89 | def while_false():
|
unreachable.py:91:9: PLW0101 Unreachable code in `while_false`
|
89 | def while_false():
90 | while False:
91 | return "unreachable"
| ^^^^^^^^^^^^^^^^^^^^ PLW0101
92 | return "reachable"
|
unreachable.py:96:9: PLW0101 Unreachable code in `while_false_else`
|
94 | def while_false_else():
95 | while False:
96 | return "unreachable"
| ^^^^^^^^^^^^^^^^^^^^ PLW0101
97 | else:
98 | return "reachable"
|
unreachable.py:102:9: PLW0101 Unreachable code in `while_false_else_return`
|
100 | def while_false_else_return():
101 | while False:
102 | return "unreachable"
| ^^^^^^^^^^^^^^^^^^^^ PLW0101
103 | else:
104 | return "reachable"
|
unreachable.py:105:5: PLW0101 Unreachable code in `while_false_else_return`
|
103 | else:
104 | return "reachable"
105 | return "also unreachable"
| ^^^^^^^^^^^^^^^^^^^^^^^^^ PLW0101
106 |
107 | def while_true():
|
unreachable.py:110:5: PLW0101 Unreachable code in `while_true`
|
108 | while True:
109 | return "reachable"
110 | return "unreachable"
| ^^^^^^^^^^^^^^^^^^^^ PLW0101
111 |
112 | def while_true_else():
|
unreachable.py:116:9: PLW0101 Unreachable code in `while_true_else`
|
114 | return "reachable"
115 | else:
116 | return "unreachable"
| ^^^^^^^^^^^^^^^^^^^^ PLW0101
117 |
118 | def while_true_else_return():
|
unreachable.py:122:9: PLW0101 Unreachable code in `while_true_else_return`
|
120 | return "reachable"
121 | else:
122 | return "unreachable"
| _________^
123 | | return "also unreachable"
| |_____________________________^ PLW0101
124 |
125 | def while_false_var_i():
|
unreachable.py:128:9: PLW0101 Unreachable code in `while_false_var_i`
|
126 | i = 0
127 | while False:
128 | i += 1
| ^^^^^^ PLW0101
129 | return i
|
unreachable.py:135:5: PLW0101 Unreachable code in `while_true_var_i`
|
133 | while True:
134 | i += 1
135 | return i
| ^^^^^^^^ PLW0101
136 |
137 | def while_infinite():
|
unreachable.py:140:5: PLW0101 Unreachable code in `while_infinite`
|
138 | while True:
139 | pass
140 | return "unreachable"
| ^^^^^^^^^^^^^^^^^^^^ PLW0101
141 |
142 | def while_if_true():
|
unreachable.py:146:5: PLW0101 Unreachable code in `while_if_true`
|
144 | if True:
145 | return "reachable"
146 | return "unreachable"
| ^^^^^^^^^^^^^^^^^^^^ PLW0101
147 |
148 | def while_break():
|
unreachable.py:152:9: PLW0101 Unreachable code in `while_break`
|
150 | print("reachable")
151 | break
152 | print("unreachable")
| ^^^^^^^^^^^^^^^^^^^^ PLW0101
153 | return "reachable"
|
unreachable.py:248:5: PLW0101 Unreachable code in `after_return`
|
246 | def after_return():
247 | return "reachable"
248 | print("unreachable")
| _____^
249 | | print("unreachable")
250 | | print("unreachable")
251 | | print("unreachable")
252 | | print("unreachable")
| |________________________^ PLW0101
|
unreachable.py:257:5: PLW0101 Unreachable code in `check_if_url_exists`
|
255 | def check_if_url_exists(url: str) -> bool: # type: ignore[return]
256 | return True # uncomment to check URLs
257 | response = requests.head(url, allow_redirects=True)
| _____^
258 | | if response.status_code == 200:
259 | | return True
260 | | if response.status_code == 404:
261 | | return False
262 | | console.print(f"[red]Unexpected error received: {response.status_code}[/]")
263 | | response.raise_for_status()
| |_______________________________^ PLW0101
|

1
ruff.schema.json generated
View file

@ -3607,6 +3607,7 @@
"PLW0",
"PLW01",
"PLW010",
"PLW0101",
"PLW0108",
"PLW012",
"PLW0120",