generators can now be indexed, don't know if this is a good thing. however, it fixes some problems with lists

This commit is contained in:
David Halter
2012-06-27 14:35:12 +02:00
parent 56a14c7811
commit 19a5d788c4
4 changed files with 38 additions and 18 deletions

View File

@@ -661,6 +661,11 @@ class Generator(object):
return self.func.parent return self.func.parent
#self.execution.get_return_types() #self.execution.get_return_types()
def get_index_types(self, index):
# TODO check if this method is right here, this means that Generators
# can be indexed, which is not the Python way.
return Execution(self.func).get_return_types(True)
def __repr__(self): def __repr__(self):
return "<%s of %s>" % (self.__class__.__name__, self.func) return "<%s of %s>" % (self.__class__.__name__, self.func)

View File

@@ -160,6 +160,7 @@ def complete(source, row, column, source_path):
if not isinstance(s, evaluate.Function): if not isinstance(s, evaluate.Function):
completions += s.get_defined_names() completions += s.get_defined_names()
#completions[0].
completions = [c for c in completions completions = [c for c in completions
if c.names[-1].lower().startswith(like.lower())] if c.names[-1].lower().startswith(like.lower())]

View File

@@ -173,21 +173,3 @@ exe[3].items
#? set() #? set()
exe[3]['c'] exe[3]['c']
# -----------------
# generators
# -----------------
def gen():
yield 1
yield ""
gen_exe = gen()
#? ['upper']
next(gen_exe).upper
#? ['real']
next(gen_exe).real
#? int() str()
next(gen_exe)
#? int() str() list
next(gen_exe, list)

View File

@@ -0,0 +1,32 @@
# -----------------
# yield statement
# -----------------
def gen():
yield 1
yield ""
gen_exe = gen()
#? ['upper']
next(gen_exe).upper
#? ['real']
next(gen_exe).real
#? int() str()
next(gen_exe)
#? int() str() list
next(gen_exe, list)
# -----------------
# generators should be indexable?
# -----------------
def get(self):
yield 1
yield ""
arr = []
for a in arr:
arr += get()
#? int() str()
arr[0].