Rename decorate-with' to
with-decorator'
Fixes #158 Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
08fbd754b6
commit
2ef9a0fdaf
@ -703,10 +703,10 @@ class HyASTCompiler(object):
|
||||
ctx=ast.Store())],
|
||||
value=self.compile(val))
|
||||
|
||||
@builds("decorate_with")
|
||||
@builds("with_decorator")
|
||||
@checkargs(min=1)
|
||||
def compile_decorate_expression(self, expr):
|
||||
expr.pop(0) # decorate-with
|
||||
expr.pop(0) # with-decorator
|
||||
fn = self.compile(expr.pop(-1))
|
||||
if type(fn) != ast.FunctionDef:
|
||||
raise HyTypeError(expr, "Decorated a non-function")
|
||||
|
@ -40,7 +40,7 @@ def router(tree, rkwargs=None):
|
||||
route = HyExpression([HySymbol("kwapply"), route,
|
||||
HyDict({HyString("methods"): rkwargs})])
|
||||
|
||||
return HyExpression([HySymbol("decorate_with"), route, tree])
|
||||
return HyExpression([HySymbol("with_decorator"), route, tree])
|
||||
|
||||
|
||||
@macro("route")
|
||||
|
@ -64,7 +64,7 @@ class FunctionMangle(HoistableMangle):
|
||||
an anon function "((fn [] ...))", or using it as an arg in a call)
|
||||
"""
|
||||
|
||||
ignore = ["def", "decorate_with", "setf", "setv", "foreach", "do"]
|
||||
ignore = ["def", "with_decorator", "setf", "setv", "foreach", "do"]
|
||||
# ^^ these guys don't affect us, really.
|
||||
|
||||
def __init__(self):
|
||||
|
@ -6,3 +6,4 @@ from .native_tests.math import * # noqa
|
||||
from .native_tests.language import * # noqa
|
||||
from .native_tests.unless import * # noqa
|
||||
from .native_tests.when import * # noqa
|
||||
from .native_tests.with_decorator import * # noqa
|
||||
|
@ -322,7 +322,7 @@ def test_ast_anon_fns_basics():
|
||||
|
||||
def test_ast_non_decoratable():
|
||||
""" Ensure decorating garbage breaks """
|
||||
cant_compile("(decorate-with (foo) (* x x))")
|
||||
cant_compile("(with-decorator (foo) (* x x))")
|
||||
|
||||
|
||||
def test_ast_non_kwapplyable():
|
||||
|
@ -132,20 +132,6 @@
|
||||
(assert (is (isfile ".") false)))
|
||||
|
||||
|
||||
(defn foodec [func]
|
||||
(lambda [] (+ 1 1)))
|
||||
|
||||
|
||||
(decorate-with foodec
|
||||
(defn tfunction []
|
||||
(* 2 2)))
|
||||
|
||||
|
||||
(defn test-decorators []
|
||||
"NATIVE: test decorators."
|
||||
(assert (= (tfunction) 2)))
|
||||
|
||||
|
||||
(defn test-kwargs []
|
||||
"NATIVE: test kwargs things."
|
||||
(assert (= (kwapply (kwtest) {"one" "two"}) {"one" "two"})))
|
||||
|
12
tests/native_tests/with_decorator.hy
Normal file
12
tests/native_tests/with_decorator.hy
Normal file
@ -0,0 +1,12 @@
|
||||
(defn foodec [func]
|
||||
(lambda [] (+ 1 1)))
|
||||
|
||||
|
||||
(with-decorator foodec
|
||||
(defn tfunction []
|
||||
(* 2 2)))
|
||||
|
||||
|
||||
(defn test-decorators []
|
||||
"NATIVE: test decorators."
|
||||
(assert (= (tfunction) 2)))
|
Loading…
Reference in New Issue
Block a user