Пример #1
0
    def check_override(self, override, original, name, supertype, node):
        """Check a method override with given signatures.

        Arguments:
          override:  The signature of the overriding method.
          original:  The signature of the original supertype method.
          name:      The name of the subtype. This and the next argument are
                     only used for generating error messages.
          supertype: The name of the supertype.
        """
        if (isinstance(override, Overloaded) or
                isinstance(original, Overloaded) or
                len((override).arg_types) !=
                    len((original).arg_types) or
                (override).min_args !=
                    (original).min_args):
            if not is_subtype(override, original):
                self.msg.signature_incompatible_with_supertype(
                    name, supertype, node)
            return
        else:
            # Give more detailed messages for the common case of both
            # signatures having the same number of arguments and no
            # intersection types.
            
            coverride = override
            coriginal = original
            
            for i in range(len(coverride.arg_types)):
                if not is_equivalent(coriginal.arg_types[i],
                                     coverride.arg_types[i]):
                    self.msg.argument_incompatible_with_supertype(
                        i + 1, name, supertype, node)
            
            if not is_subtype(coverride.ret_type, coriginal.ret_type):
                self.msg.return_type_incompatible_with_supertype(
                    name, supertype, node)
Пример #2
0
        for iface in t.typ.interfaces:
            res.append(map_instance_to_supertype(t, iface))
        
        if t.typ.base is not None:
            tt = map_instance_to_supertype(t, t.typ.base)
            res.extend(implemented_interfaces(tt))
        
        return res


bool is_similar_callables(Callable t, Callable s):
    """Return True if t and s are equivalent and have identical numbers of
    arguments, default arguments and varargs.
    """
    return (len(t.arg_types) == len(s.arg_types) and t.min_args == s.min_args
            and t.is_var_arg == s.is_var_arg and is_equivalent(t, s))


Callable combine_similar_callables(Callable t, Callable s,
                                   checker.BasicTypes basic):
    Typ[] arg_types = []
    for i in range(len(t.arg_types)):
        arg_types.append(join_types(t.arg_types[i], s.arg_types[i], basic))
    # TODO kinds and argument names
    return Callable(arg_types,
                    t.arg_kinds,
                    t.arg_names,
                    join_types(t.ret_type, s.ret_type, basic),
                    t.is_type_obj() and s.is_type_obj(),
                    None,
                    t.variables)
Пример #3
0
def is_similar_callables(t, s):
    """Return True if t and s are equivalent and have identical numbers of
    arguments, default arguments and varargs.
    """
    return (len(t.arg_types) == len(s.arg_types) and t.min_args == s.min_args
            and t.is_var_arg == s.is_var_arg and is_equivalent(t, s))
Пример #4
0
 def check_type_equivalency(self, t1, t2, node, msg=messages.INCOMPATIBLE_TYPES):
     """Generate an error if the types are not equivalent. The
     dynamic type is equivalent with all types.
     """
     if not is_equivalent(t1, t2):
         self.fail(msg, node)