Exemplo n.º 1
0
def is_simple_override(fdef: FuncDef, info: TypeInfo) -> bool:
    """Is function an override with the same type precision as the original?
    
    Compare to the original method in the superclass of info.
    """
    # If this is not an override, this can't be a simple override either.
    # Generic inheritance is not currently supported, since we need to map
    # type variables between types; in the future this restriction can be
    # lifted.
    if len(info.mro) <= 1:
        return False
    base = info.mro[1]
    if base.type_vars != []:
        return False
    orig = base.get_method(fdef.name())
    # Ignore the first argument (self) when determining type sameness.
    # TODO overloads
    newtype = cast(Callable, function_type(fdef))
    newtype = replace_self_type(newtype, AnyType())
    origtype = cast(Callable, function_type(orig))
    origtype = replace_self_type(origtype, AnyType())
    return is_same_type(newtype, origtype)
Exemplo n.º 2
0
def is_simple_override(fdef: FuncDef, info: TypeInfo) -> bool:
    """Is function an override with the same type precision as the original?
    
    Compare to the original method in the superclass of info.
    """
    # If this is not an override, this can't be a simple override either.
    # Generic inheritance is not currently supported, since we need to map
    # type variables between types; in the future this restriction can be
    # lifted.
    if len(info.mro) <= 1:
        return False
    base = info.mro[1]
    if base.type_vars != []:
        return False
    orig = base.get_method(fdef.name())
    # Ignore the first argument (self) when determining type sameness.
    # TODO overloads
    newtype = cast(Callable, function_type(fdef))
    newtype = replace_self_type(newtype, AnyType())
    origtype = cast(Callable, function_type(orig))
    origtype = replace_self_type(origtype, AnyType())
    return is_same_type(newtype, origtype)
Exemplo n.º 3
0
bool is_simple_override(FuncDef fdef, TypeInfo info):
    """Is function an override with the same type precision as the original?
    
    Compare to the original method in the superclass of info.
    """
    # If this is not an override, this can't be a simple override either.
    # Generic inheritance is not currently supported, since we need to map
    # type variables between types; in the future this restriction can be
    # lifted.
    if info.base is None or info.base.type_vars != []:
        return False
    orig = info.base.get_method(fdef.name())
    # Ignore the first argument (self) when determining type sameness.
    # TODO overloads
    newtype = (Callable)function_type(fdef)
    newtype = replace_self_type(newtype, Any())
    origtype = (Callable)function_type(orig)
    origtype = replace_self_type(origtype, Any())
    return is_same_type(newtype, origtype)


str tvar_slot_name(int n, any is_alt=False):
    """Return the name of the member that holds the runtime value of the given
    type variable slot.
    """
    if is_alt != BOUND_VAR:
        if n == 0:
            return '__tv'
        else:
            return '__tv{}'.format(n + 1)
    else: