コード例 #1
0
ファイル: infer_type.py プロジェクト: rlugojr/dotty
def infer_type(expr, scope):
    """Try to infer the type of x.y if y is a known value (literal)."""
    # Do we know what the member is?
    if isinstance(expr.member, ast.Literal):
        member = expr.member.value
    else:
        return protocol.AnyType

    container_type = infer_type(expr.obj, scope)

    try:
        # We are not using lexical scope here on purpose - we want to see what
        # the type of the member is only on the container_type.
        return structured.reflect(container_type, member) or protocol.AnyType
    except NotImplementedError:
        return protocol.AnyType
コード例 #2
0
ファイル: solve.py プロジェクト: kleopatra999/dotty
def solve_isinstance(expr, vars):
    """Typecheck whether LHS is type on the RHS."""
    lhs = solve(expr.lhs, vars)
    t = structured.reflect(vars, expr.rhs)
    return Result(protocol.implements(lhs.value, t), ())