@@ -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
118118def detect_lambda (tree , * , collect , stop , ** kw ):
0 commit comments