def check_argument_types(self, arg_types, arg_kinds, callee, formal_to_actual, context): """Check argument types against a callable type. Report errors if the argument types are not compatible. """ # Keep track of consumed tuple *arg items. tuple_counter = [0] for i, actuals in enumerate(formal_to_actual): for actual in actuals: arg_type = arg_types[actual] # Check that a *arg is valid as varargs. if (arg_kinds[actual] == nodes.ARG_STAR and not self.is_valid_var_arg(arg_type)): self.msg.invalid_var_arg(arg_type, context) if (arg_kinds[actual] == nodes.ARG_STAR2 and not self.is_valid_keyword_var_arg(arg_type)): self.msg.invalid_keyword_var_arg(arg_type, context) # Get the type of an inidividual actual argument (for *args # and **args this is the item type, not the collection type). actual_type = get_actual_type(arg_type, arg_kinds[actual], tuple_counter) self.check_arg(actual_type, arg_type, callee.arg_types[i], actual + 1, callee, context) # There may be some remaining tuple varargs items that haven't # been checked yet. Handle them. if (callee.arg_kinds[i] == nodes.ARG_STAR and arg_kinds[actual] == nodes.ARG_STAR and isinstance(arg_types[actual], TupleType)): tuplet = arg_types[actual] while tuple_counter[0] < len(tuplet.items): actual_type = get_actual_type(arg_type, arg_kinds[actual], tuple_counter) self.check_arg(actual_type, arg_type, callee.arg_types[i], actual + 1, callee, context)
""" # Keep track of consumed tuple *arg items. tuple_counter = [0] for i, actuals in enumerate(formal_to_actual): for actual in actuals: arg_type = arg_types[actual] # Check that a *arg is valid as varargs. if (arg_kinds[actual] == nodes.ARG_STAR and not self.is_valid_var_arg(arg_type)): self.msg.invalid_var_arg(arg_type, context) if (arg_kinds[actual] == nodes.ARG_STAR2 and not self.is_valid_keyword_var_arg(arg_type)): self.msg.invalid_keyword_var_arg(arg_type, context) # Get the type of an inidividual actual argument (for *args # and **args this is the item type, not the collection type). actual_type = get_actual_type(arg_type, arg_kinds[actual], tuple_counter) self.check_arg(actual_type, arg_type, callee.arg_types[i], actual + 1, callee, context) # There may be some remaining tuple varargs items that haven't # been checked yet. Handle them. if (callee.arg_kinds[i] == nodes.ARG_STAR and arg_kinds[actual] == nodes.ARG_STAR and isinstance(arg_types[actual], TupleType)): tuplet = (TupleType)arg_types[actual] while tuple_counter[0] < len(tuplet.items): actual_type = get_actual_type(arg_type, arg_kinds[actual], tuple_counter) self.check_arg(actual_type, arg_type,