Allow comprehensions with no looping parts
This commit is contained in:
parent
e1972c535f
commit
4754b152a9
@ -1094,6 +1094,13 @@ class HyASTCompiler(object):
|
||||
# Compile the parts.
|
||||
if is_for:
|
||||
parts = parts[0]
|
||||
if not parts:
|
||||
return Result(expr=ast.parse({
|
||||
asty.For: "None",
|
||||
asty.ListComp: "[]",
|
||||
asty.DictComp: "{}",
|
||||
asty.SetComp: "{1}.__class__()",
|
||||
asty.GeneratorExp: "(_ for _ in [])"}[node_class]).body[0].value)
|
||||
parts = [
|
||||
Tag(p.tag, self.compile(p.value) if p.tag in ["if", "do"] else [
|
||||
self._storeize(p.value[0], self.compile(p.value[0])),
|
||||
|
@ -98,6 +98,18 @@
|
||||
(assert (= (sorted result) answer) (str expr)))))
|
||||
|
||||
|
||||
(defn test-fors-no-loopers []
|
||||
|
||||
(setv l [])
|
||||
(for [] (.append l 1))
|
||||
(assert (= l []))
|
||||
|
||||
(assert (= (lfor 1) []))
|
||||
(assert (= (sfor 1) #{}))
|
||||
(assert (= (list (gfor 1)) []))
|
||||
(assert (= (dfor [1 2]) {})))
|
||||
|
||||
|
||||
(defn test-raise-in-comp []
|
||||
(defclass E [Exception] [])
|
||||
(setv l [])
|
||||
|
Loading…
x
Reference in New Issue
Block a user