Mangle keyword arguments
This commit is contained in:
parent
d252bb0e94
commit
0c816f2e83
@ -503,10 +503,11 @@ class HyASTCompiler(object):
|
||||
compiled_value = self.compile(value)
|
||||
ret += compiled_value
|
||||
|
||||
# no unicode for py2 in ast names
|
||||
keyword = str(expr[2:])
|
||||
if "-" in keyword and keyword != "-":
|
||||
keyword = keyword.replace("-", "_")
|
||||
keyword = expr[2:]
|
||||
if not keyword:
|
||||
raise HyTypeError(expr, "Can't call a function with the "
|
||||
"empty keyword")
|
||||
keyword = ast_str(keyword)
|
||||
|
||||
keywords.append(asty.keyword(
|
||||
expr, arg=keyword, value=compiled_value.force_expr))
|
||||
|
@ -1232,11 +1232,7 @@
|
||||
(assert (= : :))
|
||||
(assert (keyword? :))
|
||||
(assert (!= : ":"))
|
||||
(assert (= (name :) ""))
|
||||
|
||||
(defn f [&kwargs kwargs]
|
||||
(list (.items kwargs)))
|
||||
(assert (= (f : 3) [(, "" 3)])))
|
||||
(assert (= (name :) "")))
|
||||
|
||||
|
||||
(defn test-nested-if []
|
||||
|
@ -129,6 +129,27 @@
|
||||
(assert (= hyx_Xplus_signX 3))))
|
||||
|
||||
|
||||
(defn test-keyword-args []
|
||||
|
||||
(defn f [a a-b foo? ☘]
|
||||
[a a-b foo? ☘])
|
||||
(assert (= (f :foo? 3 :☘ 4 :a 1 :a-b 2) [1 2 3 4]))
|
||||
(if PY3
|
||||
(assert (= (f :is_foo 3 :hyx_ΔshamrockΔ 4 :a 1 :a_b 2) [1 2 3 4]))
|
||||
(assert (= (f :is_foo 3 :hyx_XshamrockX 4 :a 1 :a_b 2) [1 2 3 4])))
|
||||
|
||||
(defn g [&kwargs x]
|
||||
x)
|
||||
(setv sk (.format "hyx_{0}shamrock{0}" (if PY3 "Δ" "X")))
|
||||
(assert (= (g :foo? 3 :☘ 4 :a 1 :a-b 2)
|
||||
{"a" 1 "a_b" 2 "is_foo" 3 sk 4}))
|
||||
(if PY3
|
||||
(assert (= (g :is_foo 3 :hyx_ΔshamrockΔ 4 :a 1 :a_b 2)
|
||||
{"a" 1 "a_b" 2 "is_foo" 3 sk 4}))
|
||||
(assert (= (g :is_foo 3 :hyx_XshamrockX 4 :a 1 :a_b 2)
|
||||
{"a" 1 "a_b" 2 "is_foo" 3 sk 4}))))
|
||||
|
||||
|
||||
(defn test-late-mangling []
|
||||
; Mangling should only happen during compilation.
|
||||
(assert (!= 'foo? 'is_foo))
|
||||
|
Loading…
Reference in New Issue
Block a user