Skip to content

Commit 175cf5f

Browse files
committed
Added implicit-return to Python functions
This is important when working with clusters, as it differentiates between the case where the cluster has a return and when it does not.
1 parent 8c530af commit 175cf5f

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/control-flow/cfg-python.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,15 @@ export class CFGBuilder {
3535
const bodyNode = functionNode.childForFieldName("body");
3636
if (bodyNode) {
3737
const blockHandler = new BlockHandler();
38-
const { entry } = blockHandler.update(
38+
const { entry, exit } = blockHandler.update(
3939
this.processStatements(bodyNode.namedChildren),
4040
);
4141

4242
const startNode = this.addNode("START", "START");
43+
const endNode = this.addNode("RETURN", "implicit return");
4344
// `entry` will be non-null for any valid code
4445
if (entry) this.addEdge(startNode, entry);
46+
if (exit) this.addEdge(exit, endNode)
4547
this.entry = startNode;
4648
}
4749
return { graph: this.graph, entry: this.entry };

src/test/commentTestSamples/sample.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,5 +163,15 @@ def try_finally():
163163
if x:
164164
return
165165
pass
166+
finally:
167+
pass
168+
169+
# exits: 5,
170+
# render: true
171+
def try_finally():
172+
try:
173+
with x:
174+
return
175+
pass
166176
finally:
167177
pass

0 commit comments

Comments
 (0)