list comprehensions should be able to serve as an input for dynamic params as well.

This commit is contained in:
Dave Halter
2014-06-11 21:54:18 +02:00
parent 63868feb5d
commit 43e54b6173
3 changed files with 18 additions and 4 deletions

View File

@@ -206,10 +206,10 @@ class Evaluator(object):
# The string tokens are just operations (+, -, etc.) # The string tokens are just operations (+, -, etc.)
elif isinstance(element, compiled.CompiledObject): elif isinstance(element, compiled.CompiledObject):
return [element] return [element]
elif not isinstance(element, Token): elif isinstance(element, Token):
return self.eval_call(element)
else:
return [] return []
else:
return self.eval_call(element)
def eval_call(self, call): def eval_call(self, call):
"""Follow a call is following a function, variable, string, etc.""" """Follow a call is following a function, variable, string, etc."""
@@ -219,7 +219,8 @@ class Evaluator(object):
s = call s = call
while not s.parent.isinstance(pr.IsScope): while not s.parent.isinstance(pr.IsScope):
s = s.parent s = s.parent
return self.eval_call_path(path, s.parent, s.start_pos) par = s.parent
return self.eval_call_path(path, par, s.start_pos)
def eval_call_path(self, path, scope, position): def eval_call_path(self, path, scope, position):
""" """

View File

@@ -161,6 +161,9 @@ def scan_statement_for_calls(stmt, search_name, assignment_details=False):
if s_new.execution is not None: if s_new.execution is not None:
result += scan_array(s_new.execution, search_name) result += scan_array(s_new.execution, search_name)
s_new = s_new.next s_new = s_new.next
elif isinstance(c, pr.ListComprehension):
for s in c.stmt, c.middle, c.input:
result += scan_statement_for_calls(s, search_name)
return result return result

View File

@@ -394,3 +394,13 @@ def third():
return list(b) return list(b)
#? #?
third()[0] third()[0]
# -----------------
# list comprehensions
# -----------------
def from_comprehension(foo):
#? float()
return foo
[from_comprehension(1.0) for n in (1,)]