From 2ef9a0fdafb9263d29abd3f7ae3b2cb011f5a69e Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Sun, 28 Apr 2013 17:14:22 +0200 Subject: [PATCH] Rename `decorate-with' to `with-decorator' Fixes #158 Signed-off-by: Julien Danjou --- hy/compiler.py | 4 ++-- hy/contrib/meth.py | 2 +- hy/core/mangles.py | 2 +- tests/__init__.py | 1 + tests/compilers/test_ast.py | 2 +- tests/native_tests/language.hy | 14 -------------- tests/native_tests/with_decorator.hy | 12 ++++++++++++ 7 files changed, 18 insertions(+), 19 deletions(-) create mode 100644 tests/native_tests/with_decorator.hy diff --git a/hy/compiler.py b/hy/compiler.py index c6f63ad..47e3eb8 100644 --- a/hy/compiler.py +++ b/hy/compiler.py @@ -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") diff --git a/hy/contrib/meth.py b/hy/contrib/meth.py index 4f64863..859f7f6 100644 --- a/hy/contrib/meth.py +++ b/hy/contrib/meth.py @@ -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") diff --git a/hy/core/mangles.py b/hy/core/mangles.py index d60a8b3..a9cc588 100644 --- a/hy/core/mangles.py +++ b/hy/core/mangles.py @@ -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): diff --git a/tests/__init__.py b/tests/__init__.py index 997a467..6f87e4d 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -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 diff --git a/tests/compilers/test_ast.py b/tests/compilers/test_ast.py index bb0eaed..3f1893b 100644 --- a/tests/compilers/test_ast.py +++ b/tests/compilers/test_ast.py @@ -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(): diff --git a/tests/native_tests/language.hy b/tests/native_tests/language.hy index 26a444a..9722f5b 100644 --- a/tests/native_tests/language.hy +++ b/tests/native_tests/language.hy @@ -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"}))) diff --git a/tests/native_tests/with_decorator.hy b/tests/native_tests/with_decorator.hy new file mode 100644 index 0000000..dc6ad6e --- /dev/null +++ b/tests/native_tests/with_decorator.hy @@ -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)))