list comprehensions should be completeable.

This commit is contained in:
Dave Halter
2015-02-27 11:14:08 +01:00
parent f5dad437dd
commit a5728f8767
2 changed files with 16 additions and 10 deletions

View File

@@ -152,7 +152,19 @@ class Comprehension(IterableWrapper):
return "<e%s of %s>" % (type(self).__name__, self._atom)
class ListComprehension(Comprehension):
class ArrayMixin(object):
@memoize_default()
def names_dicts(self, search_global=False): # Always False.
# `array.type` is a string with the type, e.g. 'list'.
scope = self._evaluator.find_types(compiled.builtin, self.type)[0]
# builtins only have one class -> [0]
scope = self._evaluator.execute(scope, (AlreadyEvaluated((self,)),))[0]
return scope.names_dicts(search_global)
class ListComprehension(Comprehension, ArrayMixin):
type = 'list'
def get_index_types(self, evaluator, index):
return self.iter_content()
@@ -169,7 +181,7 @@ class GeneratorComprehension(Comprehension, GeneratorMixin):
return self._evaluator.eval_element(self.eval_node())
class Array(IterableWrapper):
class Array(IterableWrapper, ArrayMixin):
mapping = {'(': 'tuple',
'[': 'list',
'{': 'dict'}
@@ -242,14 +254,6 @@ class Array(IterableWrapper):
def iter_content(self):
return self.values()
@memoize_default()
def names_dicts(self, search_global=False): # Always False.
# `array.type` is a string with the type, e.g. 'list'.
scope = self._evaluator.find_types(compiled.builtin, self.type)[0]
# builtins only have one class -> [0]
scope = self._evaluator.execute(scope, (AlreadyEvaluated((self,)),))[0]
return scope.names_dicts(search_global)
@common.safe_property
def parent(self):
return compiled.builtin

View File

@@ -128,6 +128,8 @@ for i in range(10):
a = ['' for a in [1]]
#? str()
a[0]
#? ['insert']
a.insert
a = [a for a in [1]]
#? int()