Merge pull request #1321 from Kodiologist/no-str-as-sym

Require HySymbols instead of HyStrings in more cases
This commit is contained in:
Tuukka Turto 2017-07-12 22:11:36 +03:00 committed by GitHub
commit 678998f00c
4 changed files with 13 additions and 4 deletions

1
NEWS
View File

@ -14,6 +14,7 @@ Changes from 0.13.0
* Numeric literals are no longer parsed as symbols when followed by a dot
and a symbol
* Hy now respects the environment variable PYTHONDONTWRITEBYTECODE
* String literals should no longer be interpreted as special forms or macros
Changes from 0.12.1

View File

@ -2004,7 +2004,7 @@ class HyASTCompiler(object):
if isinstance(fn, HyKeyword):
return self._compile_keyword_call(expression)
if isinstance(fn, HyString):
if isinstance(fn, HySymbol):
ret = self.compile_atom(fn, expression)
if ret:
return ret
@ -2240,7 +2240,7 @@ class HyASTCompiler(object):
args[i] = var = HySymbol(self.get_anon_var())
expression = HyExpression([
HyExpression([
HyString("setv"), arg, var
HySymbol("setv"), arg, var
])]
) + expression
expression = expression.replace(arg[0])

View File

@ -3,7 +3,7 @@
# license. See the LICENSE.
from inspect import getargspec, formatargspec
from hy.models import replace_hy_obj, HyExpression, HyString
from hy.models import replace_hy_obj, HyExpression, HySymbol
from hy.errors import HyTypeError, HyMacroExpansionError
@ -179,7 +179,7 @@ def macroexpand_1(tree, compiler):
opts = {}
if isinstance(fn, HyString):
if isinstance(fn, HySymbol):
m = _hy_macros[compiler.module_name].get(fn)
if m is None:
m = _hy_macros[None].get(fn)

View File

@ -169,6 +169,14 @@
(assert (= e.message "Can't assign or delete a HyInteger")))))
(defn test-no-str-as-sym []
"Don't treat strings as symbols in the calling position"
(with [(pytest.raises TypeError)] ("setv" True 3)) ; A special form
(with [(pytest.raises TypeError)] ("abs" -2)) ; A function
(with [(pytest.raises TypeError)] ("when" 1 2)) ; A macro
None) ; Avoid https://github.com/hylang/hy/issues/1320
(defn test-fn-corner-cases []
"NATIVE: tests that fn/defn handles corner cases gracefully"
(try (eval '(fn "foo"))