Skip to content

Commit 8f3dd7e

Browse files
committed
fix isx usage
1 parent ac0cc4c commit 8f3dd7e

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

unpythonic/syntax/tailtools.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from macropy.core.hquotes import macros, hq
2121
from macropy.core.walkers import Walker
2222

23-
from .util import isx, isec, \
23+
from .util import isx, make_isxpred, isec, \
2424
detect_callec, detect_lambda, \
2525
has_tco, sort_lambda_decorators, \
2626
suggest_decorator_index
@@ -29,7 +29,7 @@
2929

3030
from ..dynassign import dyn
3131
from ..it import uniqify
32-
from ..fun import identity
32+
from ..fun import identity, orf
3333
from ..tco import trampolined, jump
3434
from ..lazyutil import mark_lazy
3535

@@ -557,6 +557,7 @@ def _tco_transform_lambda(tree, *, preproc_cb, userlambdas, known_ecs, transform
557557

558558
# Tail-position analysis for a return-value expression (also the body of a lambda).
559559
# Here we need to be very, very selective about where to recurse so this is not a Walker.
560+
_isjump = orf(make_isxpred("jump"), make_isxpred("loop"))
560561
def _transform_retexpr(tree, known_ecs, call_cb=None, data_cb=None):
561562
"""Analyze and TCO a return-value expression or a lambda body.
562563
@@ -607,7 +608,7 @@ def transform(tree):
607608
# - Hence, transform_return() calls us on the content of
608609
# all ec nodes directly. ec(...) is like return; the
609610
# argument is the retexpr.
610-
if not (isx(tree.func, "jump") or isx(tree.func, "loop") or isec(tree, known_ecs)):
611+
if not (isx(tree.func, _isjump) or isec(tree, known_ecs)):
611612
tree.args = [tree.func] + tree.args
612613
tree.func = hq[jump]
613614
tree = transform_call(tree)

unpythonic/syntax/util.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def g(ec): # <-- should grab from here
103103
fallbacks = ["ec", "brk"]
104104
for x in fallbacks:
105105
collect(x)
106-
iscallec = partial(isx, x="call_ec")
106+
iscallec = partial(isx, make_isxpred("call_ec"))
107107
# TODO: add support for general use of call_ec as a function (difficult)
108108
if type(tree) in (FunctionDef, AsyncFunctionDef) and any(iscallec(deco) for deco in tree.decorator_list):
109109
fdef = tree
@@ -142,6 +142,8 @@ def detect_lambda(tree, *, collect, stop, **kw):
142142
def is_decorator(tree, fname):
143143
"""Test tree whether it is the decorator ``fname``.
144144
145+
``fname`` may be ``str`` or a predicate, see ``isx``.
146+
145147
References of the forms ``f``, ``foo.f`` and ``hq[f]`` are supported.
146148
147149
We detect:

0 commit comments

Comments
 (0)