diff --git a/evaluate.py b/evaluate.py index a96d0755..3285a82b 100644 --- a/evaluate.py +++ b/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 diff --git a/mixin/__builtin__.py b/mixin/__builtin__.py index 8d92240d..e39b76dc 100644 --- a/mixin/__builtin__.py +++ b/mixin/__builtin__.py @@ -1,5 +1,5 @@ -def next(iterator, default=1): +def next(iterator, default=None): if hasattr("next"): return iterator.next() else: diff --git a/parsing.py b/parsing.py index be503500..16aa8cf2 100644 --- a/parsing.py +++ b/parsing.py @@ -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()) diff --git a/test/completion/functions.py b/test/completion/functions.py index e27bce14..3b33b598 100644 --- a/test/completion/functions.py +++ b/test/completion/functions.py @@ -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)