Skip to content

Commit 5372a66

Browse files
committed
remove unpythonic.syntax.util.splice, use mcpyrate.splicing.splice_expression
1 parent 5a3448c commit 5372a66

File tree

4 files changed

+8
-35
lines changed

4 files changed

+8
-35
lines changed

unpythonic/syntax/forall.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66
from mcpyrate.quotes import macros, q, u, n, a, h # noqa: F401
77

8-
from .util import splice
8+
from mcpyrate.splicing import splice_expression
9+
910
from .letdoutil import isenvassign, UnexpandedEnvAssignView
1011
from ..amb import monadify
1112
from ..amb import insist, deny # for re-export only # noqa: F401
@@ -47,7 +48,7 @@ def build(lines, tree):
4748
else:
4849
body = Mv
4950
if tree:
50-
newtree = splice(tree, body, "_here_")
51+
newtree = splice_expression(body, tree, "_here_")
5152
else:
5253
newtree = body
5354
return build(rest, newtree)

unpythonic/syntax/lambdatools.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from macropy.quick_lambda import f, _ # _ for re-export only # noqa: F401
1414

1515
from mcpyrate import gensym
16+
from mcpyrate.splicing import splice_expression
1617

1718
from ..dynassign import dyn
1819
from ..misc import namelambda
@@ -23,7 +24,7 @@
2324
from .letdo import do
2425
from .letdoutil import islet, isenvassign, UnexpandedLetView, UnexpandedEnvAssignView, ExpandedDoView
2526
from .util import (is_decorated_lambda, isx, make_isxpred, has_deco,
26-
destructure_decorated_lambda, detect_lambda, splice)
27+
destructure_decorated_lambda, detect_lambda)
2728

2829
def multilambda(block_body):
2930
@Walker
@@ -263,7 +264,7 @@ def isourupdate(thecall):
263264
theupdate = Attribute(value=q[n[ename]], attr="update")
264265
thecall = q[a[theupdate]()]
265266
thecall.keywords = kws
266-
tree.body = splice(tree.body, thecall, "_here_") # TODO: mcpyrate.splicing.splice_expression
267+
tree.body = splice_expression(thecall, tree.body, "_here_")
267268
newbindings.update({k: Attribute(value=q[n[ename]], attr=k) for k in argnames}) # "x" --> e.x
268269
set_ctx(enames=enames + [ename])
269270
set_ctx(bindings=newbindings)

unpythonic/syntax/test/test_util.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
is_lambda_decorator, is_decorated_lambda,
1515
destructure_decorated_lambda, sort_lambda_decorators,
1616
transform_statements, eliminate_ifones,
17-
splice, wrapwith, ismarker)
17+
wrapwith, ismarker)
1818

1919
from ast import Call, Name, Constant, Expr, With, withitem
2020

@@ -258,14 +258,6 @@ def ishello(tree):
258258
result = eliminate_ifones(eliminate_ifones_testdata8)
259259
test[len(result) == 1 and ishello(result[0])]
260260

261-
with testset("splice"):
262-
with q as splice_testdata:
263-
n["_here_"]
264-
n["_here_"]
265-
test[all(stmt.value.id == "_here_" for stmt in splice_testdata)]
266-
splice(splice_testdata, q[n["replacement"]], "_here_")
267-
test[all(stmt.value.id == "replacement" for stmt in splice_testdata)]
268-
269261
with testset("wrapwith"):
270262
with q as wrapwith_testdata:
271263
42 # pragma: no cover

unpythonic/syntax/util.py

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
"""Utilities for working with syntax."""
33

44
from functools import partial
5-
from copy import deepcopy
65

7-
from ast import (Call, Name, Lambda, FunctionDef, AsyncFunctionDef,
6+
from ast import (Call, Lambda, FunctionDef, AsyncFunctionDef,
87
If, With, withitem, stmt, NodeTransformer)
98

109
from macropy.core.walkers import Walker
@@ -393,26 +392,6 @@ def visit(self, node):
393392
return node
394393
return StatementTransformer().visit(body)
395394

396-
def splice(tree, rep, tag): # TODO: obsolete, replace with `mcpyrate.splicing.splice_expression`
397-
"""Splice in a tree into another tree.
398-
399-
Walk ``tree``, replacing all occurrences of a ``Name(id=tag)`` with
400-
the tree ``rep``.
401-
402-
This is convenient for first building a skeleton with a marker such as
403-
``q[n["_here_"]]``, and then splicing in ``rep`` later. See ``forall``
404-
and ``envify`` for usage examples.
405-
"""
406-
@Walker
407-
def doit(tree, *, stop, **kw):
408-
if type(tree) is Name and tree.id == tag:
409-
stop()
410-
# Copy just to be on the safe side. Different instances may be
411-
# edited differently by other macros expanded later.
412-
return deepcopy(rep)
413-
return tree
414-
return doit.recurse(tree)
415-
416395
def wrapwith(item, body, locref=None):
417396
"""Wrap ``body`` with a single-item ``with`` block, using ``item``.
418397

0 commit comments

Comments
 (0)