Skip to content

Commit

Permalink
improve processing of finallys
Browse files Browse the repository at this point in the history
  • Loading branch information
augustelalande committed Apr 22, 2024
1 parent af989a7 commit 4d724c3
Show file tree
Hide file tree
Showing 7 changed files with 278 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,31 @@ def func():
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")

Original file line number Diff line number Diff line change
Expand Up @@ -375,10 +375,10 @@ flowchart TD
start(("Start"))
return(("End"))
block0["x = 0\n"]
block1["raise Exception()\n"]
block2[["Loop continue"]]
block3["break\n"]
block4[["Exception raised"]]
block1[["Exception raised"]]
block2["raise Exception()\n"]
block3[["Loop continue"]]
block4["break\n"]
block5["assert i is not None\n"]
block6["if i == 2:
assert i is not None
Expand All @@ -392,14 +392,14 @@ flowchart TD
start --> block7
block7 -- "range(3)" --> block6
block7 -- "else" --> block1
block7 -- "else" --> block2
block6 -- "i == 2" --> block5
block6 -- "else" --> block2
block5 -- "i is not None" --> block3
block5 -- "else" --> block4
block4 --> return
block3 --> block0
block2 --> block7
block6 -- "else" --> block3
block5 -- "i is not None" --> block4
block5 -- "else" --> block1
block4 --> block0
block3 --> block7
block2 --> block1
block1 --> return
block0 --> return
```
Original file line number Diff line number Diff line change
Expand Up @@ -327,23 +327,25 @@ flowchart TD
start(("Start"))
return(("End"))
block0[["`*(empty)*`"]]
block1["raise ValueError(#quot;oops#quot;)\n"]
block2["match point:
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"]
block3["print(#quot;Origin#quot;)\n"]
block4["match point:
block4["print(#quot;Origin#quot;)\n"]
block5["match point:
case (0, 0):
print(#quot;Origin#quot;)
case _:
raise ValueError(#quot;oops#quot;)\n"]
start --> block4
block4 -- "case (0, 0)" --> block3
block4 -- "else" --> block2
block3 --> block0
start --> block5
block5 -- "case (0, 0)" --> block4
block5 -- "else" --> block3
block4 --> block0
block3 --> block2
block2 --> block1
block1 --> return
block0 --> return
Expand Down Expand Up @@ -372,8 +374,9 @@ flowchart TD
start(("Start"))
return(("End"))
block0[["`*(empty)*`"]]
block1["raise ValueError(#quot;Not a point#quot;)\n"]
block2["match point:
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):
Expand All @@ -384,8 +387,8 @@ flowchart TD
print(f#quot;X={x}, Y={y}#quot;)
case _:
raise ValueError(#quot;Not a point#quot;)\n"]
block3["print(f#quot;X={x}, Y={y}#quot;)\n"]
block4["match point:
block4["print(f#quot;X={x}, Y={y}#quot;)\n"]
block5["match point:
case (0, 0):
print(#quot;Origin#quot;)
case (0, y):
Expand All @@ -396,8 +399,8 @@ flowchart TD
print(f#quot;X={x}, Y={y}#quot;)
case _:
raise ValueError(#quot;Not a point#quot;)\n"]
block5["print(f#quot;X={x}#quot;)\n"]
block6["match point:
block6["print(f#quot;X={x}#quot;)\n"]
block7["match point:
case (0, 0):
print(#quot;Origin#quot;)
case (0, y):
Expand All @@ -408,8 +411,8 @@ flowchart TD
print(f#quot;X={x}, Y={y}#quot;)
case _:
raise ValueError(#quot;Not a point#quot;)\n"]
block7["print(f#quot;Y={y}#quot;)\n"]
block8["match point:
block8["print(f#quot;Y={y}#quot;)\n"]
block9["match point:
case (0, 0):
print(#quot;Origin#quot;)
case (0, y):
Expand All @@ -420,8 +423,8 @@ flowchart TD
print(f#quot;X={x}, Y={y}#quot;)
case _:
raise ValueError(#quot;Not a point#quot;)\n"]
block9["print(#quot;Origin#quot;)\n"]
block10["match point:
block10["print(#quot;Origin#quot;)\n"]
block11["match point:
case (0, 0):
print(#quot;Origin#quot;)
case (0, y):
Expand All @@ -433,19 +436,20 @@ flowchart TD
case _:
raise ValueError(#quot;Not a point#quot;)\n"]
start --> block10
block10 -- "case (0, 0)" --> block9
block10 -- "else" --> block8
block9 --> block0
block8 -- "case (0, y)" --> block7
block8 -- "else" --> block6
block7 --> block0
block6 -- "case (x, 0)" --> block5
block6 -- "else" --> block4
block5 --> block0
block4 -- "case (x, y)" --> block3
block4 -- "else" --> block2
block3 --> block0
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
Expand Down Expand Up @@ -790,26 +794,26 @@ flowchart TD
start(("Start"))
return(("End"))
block0[["`*(empty)*`"]]
block1["raise ValueError(#quot;oops#quot;)\n"]
block2["match point:
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"]
block3["print(#quot;Origin#quot;)\n"]
block4["match point:
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 --> block4
block4 -- "case (0, 0)" --> block3
block4 -- "else" --> block2
block3 --> block0
start --> block5
block5 -- "case (0, 0)" --> block4
block5 -- "else" --> block3
block4 --> block0
block3 --> block2
block2 --> block1
block1 --> return
block0 --> return
```


Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ def func():
flowchart TD
start(("Start"))
return(("End"))
block0["raise Exception\n"]
block0[["Exception raised"]]
block1["raise Exception\n"]
start --> block0
start --> block1
block1 --> block0
block0 --> return
```

Expand All @@ -32,10 +34,10 @@ def func():
flowchart TD
start(("Start"))
return(("End"))
block0["raise #quot;a glass!#quot;\n"]
block0[["Exception raised"]]
block1["raise #quot;a glass!#quot;\n"]
start --> block0
start --> block1
block1 --> block0
block0 --> return
```


Loading

0 comments on commit 4d724c3

Please sign in to comment.