Fixes #1350: try form in defmacro
This commit is contained in:
parent
26a4263579
commit
969fa8d533
1
NEWS
1
NEWS
@ -26,6 +26,7 @@ Changes from 0.13.0
|
|||||||
`(quit)` or `(exit)`
|
`(quit)` or `(exit)`
|
||||||
* `exec` now works under Python 2
|
* `exec` now works under Python 2
|
||||||
* No TypeError from multi-arity defn returning values evaluating to None
|
* No TypeError from multi-arity defn returning values evaluating to None
|
||||||
|
* try form now possible in defmacro/deftag
|
||||||
|
|
||||||
[ Misc. Improvements ]
|
[ Misc. Improvements ]
|
||||||
* `read`, `read_str`, and `eval` are exposed and documented as top-level
|
* `read`, `read_str`, and `eval` are exposed and documented as top-level
|
||||||
|
@ -23,6 +23,7 @@ import codecs
|
|||||||
import ast
|
import ast
|
||||||
import sys
|
import sys
|
||||||
import keyword
|
import keyword
|
||||||
|
import copy
|
||||||
|
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
|
||||||
@ -2392,7 +2393,8 @@ class HyASTCompiler(object):
|
|||||||
"""Compile-time hack: we want to get our new macro now
|
"""Compile-time hack: we want to get our new macro now
|
||||||
We must provide __name__ in the namespace to make the Python
|
We must provide __name__ in the namespace to make the Python
|
||||||
compiler set the __module__ attribute of the macro function."""
|
compiler set the __module__ attribute of the macro function."""
|
||||||
hy.importer.hy_eval(expression,
|
|
||||||
|
hy.importer.hy_eval(copy.deepcopy(expression),
|
||||||
compile_time_ns(self.module_name),
|
compile_time_ns(self.module_name),
|
||||||
self.module_name)
|
self.module_name)
|
||||||
|
|
||||||
|
@ -617,3 +617,10 @@ def test_exec_star():
|
|||||||
assert code.body.s == "print(a + b)"
|
assert code.body.s == "print(a + b)"
|
||||||
assert code.globals.keys[0].s == "a"
|
assert code.globals.keys[0].s == "a"
|
||||||
assert code.locals.keys[0].s == "b"
|
assert code.locals.keys[0].s == "b"
|
||||||
|
|
||||||
|
|
||||||
|
def test_compiler_macro_tag_try():
|
||||||
|
"""Check that try forms within defmacro/deftag are compiled correctly"""
|
||||||
|
# https://github.com/hylang/hy/issues/1350
|
||||||
|
can_compile("(defmacro foo [] (try None (except [] None)) `())")
|
||||||
|
can_compile("(deftag foo [] (try None (except [] None)) `())")
|
||||||
|
Loading…
Reference in New Issue
Block a user