Skip to content

Commit b7fa690

Browse files
committed
[GR-31314] Avoid using exception for terminating returns.
PullRequest: graalpython/1837
2 parents c0f9603 + 769e138 commit b7fa690

File tree

296 files changed

+12818
-15636
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

296 files changed

+12818
-15636
lines changed

graalpython/com.oracle.graal.python.test/src/tests/test_return.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,58 @@ def method(v):
5151

5252
assert method(10) is None
5353
assert method("value") is None
54+
55+
def test_return_in_finally():
56+
def override_explicit():
57+
try:
58+
return 0
59+
finally:
60+
return 42
61+
62+
def override_implicit():
63+
try:
64+
pass
65+
finally:
66+
return 'correct'
67+
68+
assert override_explicit() == 42
69+
assert override_implicit() == 'correct'
70+
71+
def test_return_in_try():
72+
def basic(arg):
73+
try:
74+
if arg:
75+
raise ValueError()
76+
return 1 # can be 'terminating'
77+
except ValueError as e:
78+
return 2 # can be 'terminating'
79+
80+
assert basic(True) == 2
81+
assert basic(False) == 1
82+
83+
def with_orelse(arg):
84+
try:
85+
if arg:
86+
return 'try'
87+
except:
88+
pass
89+
else:
90+
return 'else'
91+
92+
assert with_orelse(True) == 'try'
93+
assert with_orelse(False) == 'else'
94+
95+
96+
def test_return_in_try_finally():
97+
def foo(arg):
98+
try:
99+
if arg:
100+
raise ValueError()
101+
return 'try'
102+
except ValueError as e:
103+
return 'except'
104+
finally:
105+
return 'finally'
106+
107+
assert foo(True) == 'finally'
108+
assert foo(False) == 'finally'

graalpython/com.oracle.graal.python.test/testData/goldenFiles/AssignmentTests/annotationType02.tast

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@ ModuleRootNode Name: <module 'annotationType02'> SourceSection: [0,28]`def fn():
4040
IntegerLiteralNode SourceSection: [26,27]`0`
4141
Value: 0
4242
Return Expresssion: ReadLocalVariableNodeGen SourceSection: None
43-
Frame: [1,<return_val>,Illegal]
43+
Frame: [1,<return_val>,Object]

graalpython/com.oracle.graal.python.test/testData/goldenFiles/AssignmentTests/assignment06.tast

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,4 @@ ModuleRootNode Name: <module 'assignment06'> SourceSection: [0,29]`def fn():↵
6161
ReadLocalVariableNodeGen SourceSection: None
6262
Frame: [4,<>temp4,Illegal]
6363
Return Expresssion: ReadLocalVariableNodeGen SourceSection: None
64-
Frame: [5,<return_val>,Illegal]
64+
Frame: [5,<return_val>,Object]

graalpython/com.oracle.graal.python.test/testData/goldenFiles/AssignmentTests/assignment07.tast

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,4 @@ ModuleRootNode Name: <module 'assignment07'> SourceSection: [0,29]`def fn():↵
6868
ReadLocalVariableNodeGen SourceSection: None
6969
Frame: [5,<>temp5,Illegal]
7070
Return Expresssion: ReadLocalVariableNodeGen SourceSection: None
71-
Frame: [6,<return_val>,Illegal]
71+
Frame: [6,<return_val>,Object]

graalpython/com.oracle.graal.python.test/testData/goldenFiles/AssignmentTests/augassign13.tast

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@ ModuleRootNode Name: <module 'augassign13'> SourceSection: [0,17]`def fn (): x +
4444
Value: 3
4545
ObjectLiteralNode SourceSection: None
4646
Return Expresssion: ReadLocalVariableNodeGen SourceSection: None
47-
Frame: [1,<return_val>,Illegal]
47+
Frame: [1,<return_val>,Object]

graalpython/com.oracle.graal.python.test/testData/goldenFiles/AssignmentTests/augassign14.tast

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,4 @@ ModuleRootNode Name: <module 'augassign14'> SourceSection: [0,61]`def _method(*a
6767
ReadLocalVariableNodeGen SourceSection: None
6868
Frame: [5,<>temp5,Illegal]
6969
Return Expresssion: ReadLocalVariableNodeGen SourceSection: None
70-
Frame: [6,<return_val>,Illegal]
70+
Frame: [6,<return_val>,Object]

graalpython/com.oracle.graal.python.test/testData/goldenFiles/AwaitAndAsyncTests/asyncFor01.tast

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,4 @@ ModuleRootNode Name: <module 'asyncFor01'> SourceSection: [0,39]`async def f():
4848
PythonObjectFactoryNodeGen SourceSection: None
4949
BlockNode SourceSection: None
5050
Return Expresssion: ReadLocalVariableNodeGen SourceSection: None
51-
Frame: [1,<return_val>,Illegal]
51+
Frame: [1,<return_val>,Object]

graalpython/com.oracle.graal.python.test/testData/goldenFiles/AwaitAndAsyncTests/asyncFor02.tast

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,4 @@ ModuleRootNode Name: <module 'asyncFor02'> SourceSection: [0,42]`async def f():
6262
PythonObjectFactoryNodeGen SourceSection: None
6363
BlockNode SourceSection: None
6464
Return Expresssion: ReadLocalVariableNodeGen SourceSection: None
65-
Frame: [4,<return_val>,Illegal]
65+
Frame: [4,<return_val>,Object]

graalpython/com.oracle.graal.python.test/testData/goldenFiles/AwaitAndAsyncTests/asyncWith01.tast

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,4 @@ ModuleRootNode Name: <module 'asyncWith01'> SourceSection: [0,34]`async def f():
4646
YesNodeGen SourceSection: None
4747
GetClassNodeGen SourceSection: None
4848
Return Expresssion: ReadLocalVariableNodeGen SourceSection: None
49-
Frame: [0,<return_val>,Illegal]
49+
Frame: [0,<return_val>,Object]

graalpython/com.oracle.graal.python.test/testData/goldenFiles/AwaitAndAsyncTests/asyncWith02.tast

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,4 @@ ModuleRootNode Name: <module 'asyncWith02'> SourceSection: [0,47]`async def f():
6363
YesNodeGen SourceSection: None
6464
GetClassNodeGen SourceSection: None
6565
Return Expresssion: ReadLocalVariableNodeGen SourceSection: None
66-
Frame: [2,<return_val>,Illegal]
66+
Frame: [2,<return_val>,Object]

0 commit comments

Comments
 (0)