Skip to content

Commit b507d52

Browse files
committed
fix spammage in detect_callec
1 parent 8f3dd7e commit b507d52

2 files changed

Lines changed: 15 additions & 15 deletions

File tree

unpythonic/syntax/tailtools.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def transform_tailstmt(tree):
7272
def tco(block_body):
7373
# first pass, outside-in
7474
userlambdas = detect_lambda.collect(block_body)
75-
known_ecs = list(uniqify(detect_callec.collect(block_body)))
75+
known_ecs = list(uniqify(detect_callec(block_body)))
7676
block_body = yield block_body
7777

7878
# second pass, inside-out
@@ -163,7 +163,7 @@ def continuations(block_body):
163163

164164
# first pass, outside-in
165165
userlambdas = detect_lambda.collect(block_body)
166-
known_ecs = list(uniqify(detect_callec.collect(block_body)))
166+
known_ecs = list(uniqify(detect_callec(block_body)))
167167
block_body = yield block_body
168168

169169
# second pass, inside-out

unpythonic/syntax/util.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ def isec(tree, known_ecs):
7878
"""
7979
return type(tree) is Call and type(tree.func) is Name and tree.func.id in known_ecs
8080

81-
@Walker
82-
def detect_callec(tree, *, collect, **kw):
81+
def detect_callec(tree):
8382
"""Collect names of escape continuations from call_ec invocations in tree.
8483
8584
Currently supported and unsupported cases::
@@ -101,18 +100,19 @@ def g(ec): # <-- should grab from here
101100
# literal function names that are always interpreted as an ec.
102101
# "brk" is needed to combo with unpythonic.fploop.breakably_looped.
103102
fallbacks = ["ec", "brk"]
104-
for x in fallbacks:
105-
collect(x)
106103
iscallec = partial(isx, make_isxpred("call_ec"))
107-
# TODO: add support for general use of call_ec as a function (difficult)
108-
if type(tree) in (FunctionDef, AsyncFunctionDef) and any(iscallec(deco) for deco in tree.decorator_list):
109-
fdef = tree
110-
collect(fdef.args.args[0].arg) # FunctionDef.arguments.(list of arg objects).arg
111-
elif is_decorated_lambda(tree, mode="any"):
112-
decorator_list, thelambda = destructure_decorated_lambda(tree)
113-
if any(iscallec(decocall.func) for decocall in decorator_list):
114-
collect(thelambda.args.args[0].arg) # we assume it's the first arg, as that's what call_ec expects.
115-
return tree
104+
@Walker
105+
def detect(tree, *, collect, **kw):
106+
# TODO: add support for general use of call_ec as a function (difficult)
107+
if type(tree) in (FunctionDef, AsyncFunctionDef) and any(iscallec(deco) for deco in tree.decorator_list):
108+
fdef = tree
109+
collect(fdef.args.args[0].arg) # FunctionDef.arguments.(list of arg objects).arg
110+
elif is_decorated_lambda(tree, mode="any"):
111+
decorator_list, thelambda = destructure_decorated_lambda(tree)
112+
if any(iscallec(decocall.func) for decocall in decorator_list):
113+
collect(thelambda.args.args[0].arg) # we assume it's the first arg, as that's what call_ec expects.
114+
return tree
115+
return fallbacks + detect.collect(tree)
116116

117117
@Walker
118118
def detect_lambda(tree, *, collect, stop, **kw):

0 commit comments

Comments
 (0)