mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 22:44:27 +08:00
generators work again (deleted some necessary stuff)
This commit is contained in:
16
evaluate.py
16
evaluate.py
@@ -284,7 +284,6 @@ class Execution(Executable):
|
||||
elif isinstance(self.base, Generator):
|
||||
return Execution(self.base.func).get_return_types(True)
|
||||
else:
|
||||
# set the callback function to get the var_args
|
||||
# don't do this with exceptions, as usual, because some deeper
|
||||
# exceptions could be catched - and I wouldn't know what happened.
|
||||
if hasattr(self.base, 'returns'):
|
||||
@@ -315,13 +314,16 @@ class Execution(Executable):
|
||||
which act the same way as normal functions.
|
||||
"""
|
||||
def gen_param_name_copy(param, keys=[], values=[], array_type=None):
|
||||
""" Create a param with self as parent. """
|
||||
calls = parsing.Array(parsing.Array.NOARRAY, parent_stmt=self)
|
||||
"""
|
||||
Create a param with the original scope (of varargs) as parent.
|
||||
"""
|
||||
calls = parsing.Array(parsing.Array.NOARRAY,
|
||||
self.var_args.parent_stmt)
|
||||
calls.values = values
|
||||
calls.keys = keys
|
||||
calls.type = array_type
|
||||
new_param = copy.copy(param)
|
||||
new_param.parent = self
|
||||
new_param.parent = self.var_args.parent_stmt
|
||||
new_param._assignment_calls_calculated = True
|
||||
new_param._assignment_calls = calls
|
||||
name = copy.copy(param.get_name())
|
||||
@@ -513,14 +515,15 @@ class Execution(Executable):
|
||||
|
||||
|
||||
class Generator(object):
|
||||
# TODO bring next(iter, default) to work - default works not
|
||||
def __init__(self, func):
|
||||
super(Generator, self).__init__()
|
||||
self.func = func
|
||||
|
||||
def get_defined_names(self):
|
||||
"""
|
||||
Returns a list of GeneratorObject, which can return the content of a
|
||||
generator
|
||||
Returns a list of names that define a generator, which can return the
|
||||
content of a generator.
|
||||
"""
|
||||
names = []
|
||||
for n in ['__next__', 'send']:
|
||||
@@ -533,6 +536,7 @@ class Generator(object):
|
||||
name = parsing.Name([n], 0, 0, 0)
|
||||
name.parent = None
|
||||
names.append(name)
|
||||
debug.dbg('generator names', names)
|
||||
return names
|
||||
|
||||
@property
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
|
||||
def next(iterator, default=1):
|
||||
def next(iterator, default=None):
|
||||
if hasattr("next"):
|
||||
return iterator.next()
|
||||
else:
|
||||
|
||||
@@ -332,14 +332,6 @@ class Function(Scope):
|
||||
|
||||
def get_set_vars(self):
|
||||
n = super(Function, self).get_set_vars()
|
||||
"""
|
||||
if self.param_cb:
|
||||
# This is the really ugly part, where the functional style of this
|
||||
# get methods is broken, it executes a callback.
|
||||
# This is important, because something has to inject the params
|
||||
# into the functions, with the right values.
|
||||
n += self.param_cb()
|
||||
"""
|
||||
for p in self.params:
|
||||
try:
|
||||
n.append(p.get_name())
|
||||
|
||||
@@ -63,7 +63,7 @@ def recursion(a, b):
|
||||
else:
|
||||
return recursion(a+".", b+1)
|
||||
|
||||
##? int() float()
|
||||
#? int() float()
|
||||
recursion("a", 1.0)
|
||||
|
||||
# -----------------
|
||||
@@ -82,6 +82,16 @@ exe[0].index
|
||||
#? ['append']
|
||||
exe[1].append
|
||||
|
||||
# -----------------
|
||||
# default arguments
|
||||
# -----------------
|
||||
|
||||
##? int() str()
|
||||
func()
|
||||
|
||||
##? float() str()
|
||||
func(1.0)
|
||||
|
||||
# -----------------
|
||||
# closures
|
||||
# -----------------
|
||||
@@ -255,3 +265,6 @@ next(gen_exe).upper
|
||||
next(gen_exe).real
|
||||
#? int() str()
|
||||
next(gen_exe)
|
||||
|
||||
#? int() str() list
|
||||
next(gen_exe, list)
|
||||
|
||||
Reference in New Issue
Block a user