# HG changeset patch # User paulb@jeremy # Date 1161468863 -7200 # Node ID 70396fe4115ca79aef262f1582ef6cf71b884805 # Parent 7374e27f9a259ec8f265ec8b17c7ac986dfb3865 Simplified argument processing to use the pos_args and kw_args attributes in InvokeFunction instances. Added missing default value processing. diff -r 7374e27f9a25 -r 70396fe4115c annotate.py --- a/annotate.py Sat Oct 21 18:20:00 2006 +0200 +++ b/annotate.py Sun Oct 22 00:14:23 2006 +0200 @@ -524,16 +524,8 @@ "Process the arguments associated with an 'invocation'." - # NOTE: Consider initialiser invocation for classes. - - types = [] - args = [] - - # Get type information for regular arguments. - - for arg in invocation.args: - args.append(self.dispatch(arg)) - types.append(self.namespace.types) + invocation.pos_args = self.dispatches(invocation.pos_args) + invocation.kw_args = self.dispatch_dict(invocation.kw_args) # Get type information for star and dstar arguments. @@ -541,15 +533,11 @@ param, default = invocation.star default = self.dispatch(default) invocation.star = param, default - types.append(default.types) if invocation.dstar is not None: param, default = invocation.dstar default = self.dispatch(default) invocation.dstar = param, default - types.append(default.types) - - invocation.args = args def make_items(self, invocation, subprogram, context): @@ -559,27 +547,13 @@ """ if context is not None: - args = [Self(context)] + invocation.args + pos_args = [Self(context)] + invocation.pos_args else: - args = invocation.args + pos_args = invocation.pos_args + kw_args = invocation.kw_args # Sort the arguments into positional and keyword arguments. - pos_args = [] - kw_args = [] - add_kw = 0 - for arg in args: - if not add_kw: - if not isinstance(arg, Keyword): - pos_args.append(arg) - else: - add_kw = 1 - if add_kw: - if isinstance(arg, Keyword): - kw_args.append(arg) - else: - raise AnnotationMessage, "Positional argument appears after keyword arguments in '%s'." % callfunc - params = subprogram.params items = [] star_args = [] @@ -603,12 +577,14 @@ if kw_args.has_key(param): arg = kw_args[param] del kw_args[param] - elif default is None: + elif default is not None: + arg = self.dispatch(default) + else: raise AnnotationMessage, "No argument supplied in '%s' for parameter '%s'." % (subprogram, param) items.append((param, arg.types)) params = params[1:] - dstar_args = kw_args + dstar_args = kw_args.values() # Construct temporary objects.