"""Transform classes for runtime type checking."""

from typing import Undefined, List, Set, Any, cast, Tuple, Dict

from mypy.nodes import (
    TypeDef, Node, FuncDef, VarDef, Block, Var, ExpressionStmt,
    TypeInfo, SuperExpr, NameExpr, CallExpr, MDEF, MemberExpr, ReturnStmt,
    AssignmentStmt, TypeExpr, PassStmt, SymbolTableNode
)
from mypy import nodes
from mypy.semanal import self_type
from mypy.types import (
    Callable, Instance, Type, AnyType, BOUND_VAR, Void, RuntimeTypeVar,
    UnboundType
)
from mypy.checkmember import analyse_member_access
from mypy.checkexpr import type_object_type
from mypy.subtypes import map_instance_to_supertype
import mypy.transform
from mypy.transformfunc import FuncTransformer
from mypy.transutil import (
    self_expr, tvar_slot_name, tvar_arg_name, prepend_arg_type
)
from mypy.rttypevars import translate_runtime_type_vars_locally
from mypy.compileslotmap import find_slot_origin
from mypy.coerce import coerce
from mypy.maptypevar import num_slots, get_tvar_access_path
from mypy import erasetype


class TypeTransformer:
    """Class for transforming type definitions for runtime type checking.

    Transform a type definition by modifying it in-place.

    The following transformations are performed:

      * Represent generic type variables explicitly as attributes.
      * Create generic wrapper classes used by coercions to different type
        args.
      * Create wrapper methods needed when overriding methods with different
        signatures.
      * Create wrapper methods for calling methods in dynamically typed code.
        These perform the necessary coercions for arguments and return values
        to/from 'Any'.
    
    This is used by DyncheckTransformVisitor and is logically aggregated within
    that class.
    """
    
    # Used for common transformation operations.
    tf = Undefined('mypy.transform.DyncheckTransformVisitor')
    # Used for transforming methods.
    func_tf = Undefined(FuncTransformer)
    
    def __init__(self, tf: 'mypy.transform.DyncheckTransformVisitor') -> None:
        self.tf = tf
        self.func_tf = FuncTransformer(tf)
    
    def transform_type_def(self, tdef: TypeDef) -> List[Node]:        
        """Transform a type definition.

        The result may be one or two definitions.  The first is the
        transformation of the original TypeDef. The second is a
        wrapper type, which is generated for generic types only.
        """
        defs = [] # type: List[Node]
        
        if tdef.info.type_vars:
            # This is a generic type. Insert type variable slots in
            # the class definition for new type variables, i.e. type
            # variables not mapped to superclass type variables.
            defs.extend(self.make_tvar_representation(tdef.info))
        
        # Iterate over definitions and transform each of them.
        vars = set() # type: Set[Var]
        for d in tdef.defs.body:
            if isinstance(d, FuncDef):
                # Implicit cast from FuncDef[] to Node[] is safe below.
                defs.extend(Any(self.func_tf.transform_method(d)))
            elif isinstance(d, VarDef):
                defs.extend(self.transform_var_def(d))
                for n in d.items:
                    vars.add(n)
            elif isinstance(d, AssignmentStmt):
                self.transform_assignment(d)
                defs.append(d)

        # Add accessors for implicitly defined attributes.
        for node in tdef.info.names.values():
            if isinstance(node.node, Var):
                v = cast(Var, node.node)
                if v.info == tdef.info and v not in vars:
                    defs.extend(self.make_accessors(v))
        
        # For generic classes, add an implicit __init__ wrapper.
        defs.extend(self.make_init_wrapper(tdef))
        
        if tdef.is_generic() or (tdef.info.bases and
                                 tdef.info.mro[1].is_generic()):
            self.make_instance_tvar_initializer(
                cast(FuncDef, tdef.info.get_method('__init__')))

        if not defs:
            defs.append(PassStmt())

        if tdef.is_generic():
            gen_wrapper = self.generic_class_wrapper(tdef)

        tdef.defs = Block(defs)

        dyn_wrapper = self.make_type_object_wrapper(tdef)
        
        if not tdef.is_generic():
            return [tdef, dyn_wrapper]
        else:
            return [tdef, dyn_wrapper, gen_wrapper]
    
    def make_init_wrapper(self, tdef: TypeDef) -> List[Node]:
        """Make and return an implicit __init__ if class needs it.
        
        Otherwise, return an empty list. We include an implicit
        __init__ if the class is generic or if it extends a generic class
        and if it does not define __init__.
        
        The __init__ of a generic class requires one or more extra type
        variable arguments. The inherited __init__ may not accept these.

        For example, assume these definitions:
        
        . class A(Generic[T]): pass
        . class B(A[int]): pass
        
        The constructor for B will be (equivalent to)
        
        . def __init__(self: B) -> None:
        .     self.__tv = <int>
        .     super().__init__(<int>)
        """
        
        # FIX overloading, default args / varargs, keyword args

        info = tdef.info
        
        if '__init__' not in info.names and (
                tdef.is_generic() or (info.bases and
                                      info.mro[1].is_generic())):
            # Generic class with no explicit __init__ method
            # (i.e. __init__ inherited from superclass). Generate a
            # wrapper that initializes type variable slots and calls
            # the superclass __init__ method.

            base = info.mro[1]
            selftype = self_type(info)    
            callee_type = cast(Callable, analyse_member_access(
                '__init__', selftype, None, False, True, None, None,
                base))
            
            # Now the callee type may contain the type variables of a
            # grandparent as bound type variables, but we want the
            # type variables of the parent class. Explicitly set the
            # bound type variables.
            callee_type = self.fix_bound_init_tvars(callee_type,
                map_instance_to_supertype(selftype, base))
            
            super_init = cast(FuncDef, base.get_method('__init__'))
            
            # Build argument list.
            args = [Var('self')]
            for i in range(1, len(super_init.args)):
                args.append(Var(super_init.args[i].name()))
                args[-1].type = callee_type.arg_types[i - 1]

            selft = self_type(self.tf.type_context())
            callee_type = prepend_arg_type(callee_type, selft)
            
            creat = FuncDef('__init__', args,
                            super_init.arg_kinds, [None] * len(args),
                            Block([]))
            creat.info = tdef.info
            creat.type = callee_type
            creat.is_implicit = False
            tdef.info.names['__init__'] = SymbolTableNode(MDEF, creat,
                                                          typ=creat.type)
            
            # Insert a call to superclass constructor. If the
            # superclass is object, the constructor does nothing =>
            # omit the call.
            if base.fullname() != 'builtins.object':
                creat.body.body.append(
                    self.make_superclass_constructor_call(tdef.info,
                                                          callee_type))
            
            # Implicit cast from FuncDef[] to Node[] is safe below.
            return Any(self.func_tf.transform_method(creat))
        else:
            return []
    
    def fix_bound_init_tvars(self, callable: Callable,
                             typ: Instance) -> Callable:
        """Replace bound type vars of callable with args from instance type."""
        a = [] # type: List[Tuple[int, Type]]
        for i in range(len(typ.args)):
            a.append((i + 1, typ.args[i]))
        return Callable(callable.arg_types, callable.arg_kinds,
                        callable.arg_names, callable.ret_type,
                        callable.is_type_obj(), callable.name,
                        callable.variables, a)
    
    def make_superclass_constructor_call(
            self, info: TypeInfo, callee_type: Callable) -> ExpressionStmt:
        """Construct a statement that calls the superclass constructor.

        In particular, it passes any type variables arguments as needed.
        """
        callee = SuperExpr('__init__')
        callee.info = info
        
        # We do not handle generic constructors. Either pass runtime
        # type variables from the current scope or perhaps require
        # explicit constructor in this case.
        
        selftype = self_type(info)    
        
        # FIX overloading
        # FIX default args / varargs
        
        # Map self type to the superclass context.
        base = info.mro[1]
        selftype = map_instance_to_supertype(selftype, base)
        
        super_init = cast(FuncDef, base.get_method('__init__'))
        
        # Add constructor arguments.
        args = [] # type: List[Node]
        for n in range(1, callee_type.min_args):            
            args.append(NameExpr(super_init.args[n].name()))
            self.tf.set_type(args[-1], callee_type.arg_types[n])

        # Store callee type after stripping away the 'self' type.
        self.tf.set_type(callee, nodes.method_callable(callee_type))
        
        call = CallExpr(callee, args, [nodes.ARG_POS] * len(args))
        return ExpressionStmt(call)
    
    def transform_var_def(self, o: VarDef) -> List[Node]:
        """Transform a member variable definition.

        The result may be one or more definitions.
        """
        res = [o] # type: List[Node]
        
        self.tf.visit_var_def(o)
        
        # Add $x and set$x accessor wrappers for data attributes. These let
        # derived classes redefine a data attribute as a property.
        for n in o.items:
            res.extend(self.make_accessors(n))
        
        return res
    
    def transform_assignment(self, o: AssignmentStmt) -> None:
        """Transform an assignment statement in class body."""
        self.tf.visit_assignment_stmt(o)

    def make_accessors(self, n: Var) -> List[Node]:
        if n.type:
            t = n.type
        else:
            t = AnyType()
        return [self.make_getter_wrapper(n.name(), t),
                self.make_setter_wrapper(n.name(), t),
                self.make_dynamic_getter_wrapper(n.name(), t),
                self.make_dynamic_setter_wrapper(n.name(), t)]
    
    def make_getter_wrapper(self, name: str, typ: Type) -> FuncDef:
        """Create a getter wrapper for a data attribute.

        The getter will be of this form:
        
        . def $name*(self: C) -> type:
        .     return self.name!
        """
        scope = self.make_scope()
        selft = self.self_type()
        selfv = scope.add('self', selft)
        
        member_expr = MemberExpr(scope.name_expr('self'), name, direct=True)
        ret = ReturnStmt(member_expr)

        wrapper_name = '$' + name
        sig = Callable([selft], [nodes.ARG_POS], [None], typ, False)
        fdef = FuncDef(wrapper_name,
                       [selfv],
                       [nodes.ARG_POS],
                       [None],
                       Block([ret]), sig)
        fdef.info = self.tf.type_context()
        return fdef
    
    def make_dynamic_getter_wrapper(self, name: str, typ: Type) -> FuncDef:
        """Create a dynamically-typed getter wrapper for a data attribute.

        The getter will be of this form:
        
        . def $name*(self: C) -> Any:
        .     return {Any <= typ self.name!}
        """
        scope = self.make_scope()
        selft = self.self_type()
        selfv = scope.add('self', selft)
        
        member_expr = MemberExpr(scope.name_expr('self'), name, direct=True)
        coerce_expr = coerce(member_expr, AnyType(), typ,
                             self.tf.type_context())
        ret = ReturnStmt(coerce_expr)

        wrapper_name = '$' + name + self.tf.dynamic_suffix()
        sig = Callable([selft], [nodes.ARG_POS], [None], AnyType(), False)
        return FuncDef(wrapper_name,
                       [selfv],
                       [nodes.ARG_POS],
                       [None],
                       Block([ret]), sig)
    
    def make_setter_wrapper(self, name: str, typ: Type) -> FuncDef:
        """Create a setter wrapper for a data attribute.

        The setter will be of this form:
        
        . def set$name(self: C, name: typ) -> None:
        .     self.name! = name
        """
        scope = self.make_scope()
        selft = self.self_type()
        selfv = scope.add('self', selft)
        namev = scope.add(name, typ)
        
        lvalue = MemberExpr(scope.name_expr('self'), name, direct=True)
        rvalue = scope.name_expr(name)
        ret = AssignmentStmt([lvalue], rvalue)

        wrapper_name = 'set$' + name
        sig = Callable([selft, typ],
                       [nodes.ARG_POS, nodes.ARG_POS],
                       [None, None],
                       Void(), False)
        fdef = FuncDef(wrapper_name,
                       [selfv, namev],
                       [nodes.ARG_POS, nodes.ARG_POS],
                       [None, None],
                       Block([ret]), sig)
        fdef.info = self.tf.type_context()
        return fdef
    
    def make_dynamic_setter_wrapper(self, name: str, typ: Type) -> FuncDef:
        """Create a dynamically-typed setter wrapper for a data attribute.

        The setter will be of this form:
        
        . def set$name*(self: C, name; Any) -> None:
        .     self.name! = {typ name}
        """
        lvalue = MemberExpr(self_expr(), name, direct=True)
        name_expr = NameExpr(name)
        rvalue = coerce(name_expr, typ, AnyType(), self.tf.type_context())
        ret = AssignmentStmt([lvalue], rvalue)

        wrapper_name = 'set$' + name + self.tf.dynamic_suffix()
        selft = self_type(self.tf.type_context())            
        sig = Callable([selft, AnyType()],
                       [nodes.ARG_POS, nodes.ARG_POS],
                       [None, None],
                       Void(), False)
        return FuncDef(wrapper_name,
                       [Var('self'), Var(name)],
                       [nodes.ARG_POS, nodes.ARG_POS],
                       [None, None],
                       Block([ret]), sig)
    
    def generic_accessor_wrappers(self, s: AssignmentStmt) -> List[Node]:
        """Construct wrapper class methods for attribute accessors."""
        res = [] # type: List[Node]
        assert len(s.lvalues) == 1
        assert isinstance(s.lvalues[0], NameExpr)
        assert s.type is not None
        name = cast(NameExpr, s.lvalues[0])
        for fd in [self.make_getter_wrapper(name.name, s.type),
                   self.make_setter_wrapper(name.name, s.type)]:
            res.extend(self.func_tf.generic_method_wrappers(fd))
        return res
    
    def generic_class_wrapper(self, tdef: TypeDef) -> TypeDef:
        """Construct a wrapper class for a generic type."""
        # FIX semanal meta-info for nodes + TypeInfo
        
        defs = [] # type: List[Node]
        
        # Does the type have a superclass, other than builtins.object?
        base = tdef.info.mro[1]
        has_proper_superclass = base.fullname() != 'builtins.object'
        
        if not has_proper_superclass or self.tf.is_java:
            # Generate member variables for wrapper object.
            defs.extend(self.make_generic_wrapper_member_vars(tdef))
        
        for alt in [False, BOUND_VAR]:
            defs.extend(self.make_tvar_representation(tdef.info, alt))
        
        # Generate constructor.
        defs.append(self.make_generic_wrapper_init(tdef.info))
        
        # Generate method wrappers.
        for d in tdef.defs.body:
            if isinstance(d, FuncDef):
                if not d.is_constructor():
                    defs.extend(self.func_tf.generic_method_wrappers(d))
            elif isinstance(d, AssignmentStmt):
                defs.extend(self.generic_accessor_wrappers(d))
            elif not isinstance(d, PassStmt):
                raise RuntimeError(
                    'Definition {} at line {} not supported'.format(
                        type(d), d.line))
        
        base_type = self.tf.named_type('builtins.object') # type: Type
        # Inherit superclass wrapper if there is one.
        if has_proper_superclass:
            base = self.find_generic_base_class(tdef.info)
            if base:
                # TODO bind the type somewhere
                base_type = UnboundType(base.defn.name +
                                        self.tf.wrapper_class_suffix())
        
        # Build the type definition.
        wrapper = TypeDef(tdef.name + self.tf.wrapper_class_suffix(),
                          Block(defs),
                          None,
                          [base_type])
        # FIX fullname
        
        self.tf.add_line_mapping(tdef, wrapper)
        
        return wrapper
    
    def find_generic_base_class(self, info: TypeInfo) -> TypeInfo:
        base = info.mro[1]
        while True:
            if base.type_vars != []:
                return base
            if len(base.mro) <= 1:
                return None
            base = base.mro[1]
    
    def make_generic_wrapper_member_vars(self, tdef: TypeDef) -> List[Node]:
        """Generate member variable definition for wrapped object (__o).
        
        This is added to a generic wrapper class.
        """
        # The type is 'Any' since it should behave covariantly in subclasses.
        return [VarDef([Var(self.object_member_name(tdef.info),
                            AnyType())], False, None)]
    
    def object_member_name(self, info: TypeInfo) -> str:
        if self.tf.is_java:
            return '__o_{}'.format(info.name)
        else:
            return '__o'
    
    def make_generic_wrapper_init(self, info: TypeInfo) -> FuncDef:
        """Build constructor of a generic wrapper class."""
        nslots = num_slots(info)
        
        cdefs = [] # type: List[Node]
        
        # Build superclass constructor call.
        base = info.mro[1]
        if base.fullname() != 'builtins.object' and self.tf.is_java:
            s = SuperExpr('__init__')
            cargs = [NameExpr('__o')] # type: List[Node]
            for n in range(num_slots(base)):
                cargs.append(NameExpr(tvar_arg_name(n + 1)))
            for n in range(num_slots(base)):
                cargs.append(NameExpr(tvar_arg_name(n + 1, BOUND_VAR)))
            c = CallExpr(s, cargs, [nodes.ARG_POS] * len(cargs))
            cdefs.append(ExpressionStmt(c))
        
        # Create initialization of the wrapped object.
        cdefs.append(AssignmentStmt([MemberExpr(
                                         self_expr(),
                                         self.object_member_name(info),
                                         direct=True)],
                                    NameExpr('__o')))
        
        # Build constructor arguments.
        args = [Var('self'), Var('__o')]
        init = [None, None] # type: List[Node]
        
        for alt in [False, BOUND_VAR]:
            for n in range(nslots):
                args.append(Var(tvar_arg_name(n + 1, alt)))
                init.append(None)

        nargs = nslots * 2 + 2
        fdef = FuncDef('__init__',
                       args,
                       [nodes.ARG_POS] * nargs,
                       init,
                       Block(cdefs),
                       Callable( [AnyType()] * nargs,
                                [nodes.ARG_POS] * nargs, [None] * nargs,
                                Void(),
                                is_type_obj=False))
        fdef.info = info
        
        self.make_wrapper_slot_initializer(fdef)
        
        return fdef
    
    def make_tvar_representation(self, info: TypeInfo,
                                 is_alt: Any = False) -> List[Node]:
        """Return type variable slot member definitions.

        There are of form '__tv*: Any'. Only include new slots defined in the
        type.
        """
        defs = [] # type: List[Node]
        base_slots = num_slots(info.mro[1])
        for n in range(len(info.type_vars)):
            # Only include a type variable if it introduces a new slot.
            slot = get_tvar_access_path(info, n + 1)[0] - 1
            if slot >= base_slots:
                defs.append(VarDef([Var(tvar_slot_name(slot, is_alt),
                                        AnyType())], False, None))
        return defs
    
    def make_instance_tvar_initializer(self, creat: FuncDef) -> None:
        """Add type variable member initialization code to a constructor.

        Modify the constructor body directly.
        """
        for n in range(num_slots(creat.info)):
            rvalue = self.make_tvar_init_expression(creat.info, n)
            init = AssignmentStmt([MemberExpr(self_expr(),
                                              tvar_slot_name(n),
                                              direct=True)],
                                  rvalue)
            self.tf.set_type(init.lvalues[0], AnyType())
            self.tf.set_type(init.rvalue, AnyType())
            creat.body.body.insert(n, init)
    
    def make_wrapper_slot_initializer(self, creat: FuncDef) -> None:
        """Add type variable member initializations to a wrapper constructor.

        The function must be a constructor of a generic wrapper class. Modify
        the constructor body directly.
        """
        for alt in [BOUND_VAR, False]:
            for n in range(num_slots(creat.info)):
                rvalue = TypeExpr(
                    RuntimeTypeVar(NameExpr(tvar_slot_name(n, alt))))
                init = AssignmentStmt(
                    [MemberExpr(self_expr(),
                                tvar_slot_name(n, alt), direct=True)],
                    rvalue)
                self.tf.set_type(init.lvalues[0], AnyType())
                self.tf.set_type(init.rvalue, AnyType())
                creat.body.body.insert(n, init)
    
    def make_tvar_init_expression(self, info: TypeInfo, slot: int) -> TypeExpr:
        """Return the initializer for the given slot in the given type.
        
        This is the type expression that initializes the given slot
        using the type arguments given to the constructor.
        
        Examples:
          - In 'class C(Generic[T]) ...', the initializer for the slot 0 is
            TypeExpr(RuntimeTypeVar(NameExpr('__tv'))).
          - In 'class D(C[int]) ...', the initializer for the slot 0 is
            TypeExpr(<int instance>).
        """
        # Figure out the superclass which defines the slot; also figure out
        # the tvar index that maps to the slot.
        origin, tv = find_slot_origin(info, slot)
        
        # Map self type to the superclass -> extract tvar with target index
        # (only contains subclass tvars?? PROBABLY NOT).
        selftype = self_type(info)
        selftype = map_instance_to_supertype(selftype, origin)
        tvar = selftype.args[tv - 1]
        
        # Map tvar to an expression; refer to local vars instead of member
        # vars always.
        tvar = translate_runtime_type_vars_locally(tvar)
        
        # Build the rvalue (initializer) expression
        return TypeExpr(tvar)

    def make_type_object_wrapper(self, tdef: TypeDef) -> FuncDef:
        """Construct dynamically typed wrapper function for a class.

        It simple calls the type object and returns the result.
        """
        
        # TODO keyword args, default args and varargs
        # TODO overloads

        type_sig = cast(Callable, type_object_type(tdef.info, None))
        type_sig = cast(Callable, erasetype.erase_typevars(type_sig))
        
        init = cast(FuncDef, tdef.info.get_method('__init__'))
        arg_kinds = type_sig.arg_kinds

        # The wrapper function has a dynamically typed signature.
        wrapper_sig = Callable( [AnyType()] * len(arg_kinds),
                               arg_kinds, [None] * len(arg_kinds),
                               AnyType(), False)
        
        n = NameExpr(tdef.name) # TODO full name
        args = self.func_tf.call_args(
            init.args[1:],
            type_sig,
            wrapper_sig,
            True, False)
        call = CallExpr(n, args, arg_kinds)
        ret = ReturnStmt(call)
        

        fdef = FuncDef(tdef.name + self.tf.dynamic_suffix(),
                       init.args[1:],
                       arg_kinds, [None] * len(arg_kinds),
                       Block([ret]))
        
        fdef.type = wrapper_sig
        return fdef

    def self_type(self) -> Instance:
        return self_type(self.tf.type_context())

    def make_scope(self) -> 'Scope':
        return Scope(self.tf.type_map)
        

class Scope:
    """Maintain a temporary local scope during transformation."""
    def __init__(self, type_map: Dict[Node, Type]) -> None:
        self.names = {} # type: Dict[str, Var]
        self.type_map = type_map

    def add(self, name: str, type: Type) -> Var:
        v = Var(name)
        v.type = type
        self.names[name] = v
        return v

    def name_expr(self, name: str) -> NameExpr:
        nexpr = NameExpr(name)
        nexpr.kind = nodes.LDEF
        node = self.names[name]
        nexpr.node = node
        self.type_map[nexpr] = node.type
        return nexpr

[((52, 9, 52, 61), 'typing.Undefined', 'Undefined', ({(52, 19, 52, 60): '"""mypy.transform.DyncheckTransformVisitor"""'}, {}), "('mypy.transform.DyncheckTransformVisitor')", False, 'from typing import Undefined, List, Set, Any, cast, Tuple, Dict\n'), ((54, 14, 54, 40), 'typing.Undefined', 'Undefined', ({(54, 24, 54, 39): 'FuncTransformer'}, {}), '(FuncTransformer)', False, 'from typing import Undefined, List, Set, Any, cast, Tuple, Dict\n'), ((58, 23, 58, 42), 'mypy.transformfunc.FuncTransformer', 'FuncTransformer', ({(58, 39, 58, 41): 'tf'}, {}), '(tf)', False, 'from mypy.transformfunc import FuncTransformer\n'), ((110, 20, 110, 31), 'mypy.nodes.Block', 'Block', ({(110, 26, 110, 30): 'defs'}, {}), '(defs)', False, 'from mypy.nodes import TypeDef, Node, FuncDef, VarDef, Block, Var, ExpressionStmt, TypeInfo, SuperExpr, NameExpr, CallExpr, MDEF, MemberExpr, ReturnStmt, AssignmentStmt, TypeExpr, PassStmt, SymbolTableNode\n'), ((216, 17, 216, 38), 'mypy.nodes.SuperExpr', 'SuperExpr', ({(216, 27, 216, 37): '"""__init__"""'}, {}), "('__init__')", False, 'from mypy.nodes import TypeDef, Node, FuncDef, VarDef, Block, Var, ExpressionStmt, TypeInfo, SuperExpr, NameExpr, CallExpr, MDEF, MemberExpr, ReturnStmt, AssignmentStmt, TypeExpr, PassStmt, SymbolTableNode\n'), ((223, 19, 223, 34), 'mypy.semanal.self_type', 'self_type', ({(223, 29, 223, 33): 'info'}, {}), '(info)', False, 'from mypy.semanal import self_type\n'), ((230, 19, 230, 60), 'mypy.subtypes.map_instance_to_supertype', 'map_instance_to_supertype', ({(230, 45, 230, 53): 'selftype', (230, 55, 230, 59): 'base'}, {}), '(selftype, base)', False, 'from mypy.subtypes import map_instance_to_supertype\n'), ((244, 15, 244, 35), 'mypy.nodes.ExpressionStmt', 'ExpressionStmt', ({(244, 30, 244, 34): 'call'}, {}), '(call)', False, 'from mypy.nodes import TypeDef, Node, FuncDef, VarDef, Block, Var, ExpressionStmt, TypeInfo, SuperExpr, NameExpr, CallExpr, MDEF, MemberExpr, ReturnStmt, AssignmentStmt, TypeExpr, PassStmt, SymbolTableNode\n'), ((289, 14, 289, 37), 'mypy.nodes.ReturnStmt', 'ReturnStmt', ({(289, 25, 289, 36): 'member_expr'}, {}), '(member_expr)', False, 'from mypy.nodes import TypeDef, Node, FuncDef, VarDef, Block, Var, ExpressionStmt, TypeInfo, SuperExpr, NameExpr, CallExpr, MDEF, MemberExpr, ReturnStmt, AssignmentStmt, TypeExpr, PassStmt, SymbolTableNode\n'), ((292, 14, 292, 68), 'mypy.types.Callable', 'Callable', ({(292, 23, 292, 30): '[selft]', (292, 32, 292, 47): '[nodes.ARG_POS]', (292, 49, 292, 55): '[None]', (292, 57, 292, 60): 'typ', (292, 62, 292, 67): 'False'}, {}), '([selft], [nodes.ARG_POS], [None], typ, False)', False, 'from mypy.types import Callable, Instance, Type, AnyType, BOUND_VAR, Void, RuntimeTypeVar, UnboundType\n'), ((316, 14, 316, 37), 'mypy.nodes.ReturnStmt', 'ReturnStmt', ({(316, 25, 316, 36): 'coerce_expr'}, {}), '(coerce_expr)', False, 'from mypy.nodes import TypeDef, Node, FuncDef, VarDef, Block, Var, ExpressionStmt, TypeInfo, SuperExpr, NameExpr, CallExpr, MDEF, MemberExpr, ReturnStmt, AssignmentStmt, TypeExpr, PassStmt, SymbolTableNode\n'), ((341, 14, 341, 46), 'mypy.nodes.AssignmentStmt', 'AssignmentStmt', ({(341, 29, 341, 37): '[lvalue]', (341, 39, 341, 45): 'rvalue'}, {}), '([lvalue], rvalue)', False, 'from mypy.nodes import TypeDef, Node, FuncDef, VarDef, Block, Var, ExpressionStmt, TypeInfo, SuperExpr, NameExpr, CallExpr, MDEF, MemberExpr, ReturnStmt, AssignmentStmt, TypeExpr, PassStmt, SymbolTableNode\n'), ((365, 20, 365, 34), 'mypy.nodes.NameExpr', 'NameExpr', ({(365, 29, 365, 33): 'name'}, {}), '(name)', False, 'from mypy.nodes import TypeDef, Node, FuncDef, VarDef, Block, Var, ExpressionStmt, TypeInfo, SuperExpr, NameExpr, CallExpr, MDEF, MemberExpr, ReturnStmt, AssignmentStmt, TypeExpr, PassStmt, SymbolTableNode\n'), ((367, 14, 367, 46), 'mypy.nodes.AssignmentStmt', 'AssignmentStmt', ({(367, 29, 367, 37): '[lvalue]', (367, 39, 367, 45): 'rvalue'}, {}), '([lvalue], rvalue)', False, 'from mypy.nodes import TypeDef, Node, FuncDef, VarDef, Block, Var, ExpressionStmt, TypeInfo, SuperExpr, NameExpr, CallExpr, MDEF, MemberExpr, ReturnStmt, AssignmentStmt, TypeExpr, PassStmt, SymbolTableNode\n'), ((387, 15, 387, 43), 'typing.cast', 'cast', ({(387, 20, 387, 28): 'NameExpr', (387, 30, 387, 42): 's.lvalues[0]'}, {}), '(NameExpr, s.lvalues[0])', False, 'from typing import Undefined, List, Set, Any, cast, Tuple, Dict\n'), ((471, 17, 471, 32), 'mypy.maptypevar.num_slots', 'num_slots', ({(471, 27, 471, 31): 'info'}, {}), '(info)', False, 'from mypy.maptypevar import num_slots, get_tvar_access_path\n'), ((527, 21, 527, 43), 'mypy.maptypevar.num_slots', 'num_slots', ({(527, 31, 527, 42): 'info.mro[1]'}, {}), '(info.mro[1])', False, 'from mypy.maptypevar import num_slots, get_tvar_access_path\n'), ((583, 21, 583, 49), 'mypy.compileslotmap.find_slot_origin', 'find_slot_origin', ({(583, 38, 583, 42): 'info', (583, 44, 583, 48): 'slot'}, {}), '(info, slot)', False, 'from mypy.compileslotmap import find_slot_origin\n'), ((587, 19, 587, 34), 'mypy.semanal.self_type', 'self_type', ({(587, 29, 587, 33): 'info'}, {}), '(info)', False, 'from mypy.semanal import self_type\n'), ((588, 19, 588, 62), 'mypy.subtypes.map_instance_to_supertype', 'map_instance_to_supertype', ({(588, 45, 588, 53): 'selftype', (588, 55, 588, 61): 'origin'}, {}), '(selftype, origin)', False, 'from mypy.subtypes import map_instance_to_supertype\n'), ((593, 15, 593, 56), 'mypy.rttypevars.translate_runtime_type_vars_locally', 'translate_runtime_type_vars_locally', ({(593, 51, 593, 55): 'tvar'}, {}), '(tvar)', False, 'from mypy.rttypevars import translate_runtime_type_vars_locally\n'), ((596, 15, 596, 29), 'mypy.nodes.TypeExpr', 'TypeExpr', ({(596, 24, 596, 28): 'tvar'}, {}), '(tvar)', False, 'from mypy.nodes import TypeDef, Node, FuncDef, VarDef, Block, Var, ExpressionStmt, TypeInfo, SuperExpr, NameExpr, CallExpr, MDEF, MemberExpr, ReturnStmt, AssignmentStmt, TypeExpr, PassStmt, SymbolTableNode\n'), ((618, 12, 618, 31), 'mypy.nodes.NameExpr', 'NameExpr', ({(618, 21, 618, 30): 'tdef.name'}, {}), '(tdef.name)', False, 'from mypy.nodes import TypeDef, Node, FuncDef, VarDef, Block, Var, ExpressionStmt, TypeInfo, SuperExpr, NameExpr, CallExpr, MDEF, MemberExpr, ReturnStmt, AssignmentStmt, TypeExpr, PassStmt, SymbolTableNode\n'), ((624, 15, 624, 43), 'mypy.nodes.CallExpr', 'CallExpr', ({(624, 24, 624, 25): 'n', (624, 27, 624, 31): 'args', (624, 33, 624, 42): 'arg_kinds'}, {}), '(n, args, arg_kinds)', False, 'from mypy.nodes import TypeDef, Node, FuncDef, VarDef, Block, Var, ExpressionStmt, TypeInfo, SuperExpr, NameExpr, CallExpr, MDEF, MemberExpr, ReturnStmt, AssignmentStmt, TypeExpr, PassStmt, SymbolTableNode\n'), ((625, 14, 625, 30), 'mypy.nodes.ReturnStmt', 'ReturnStmt', ({(625, 25, 625, 29): 'call'}, {}), '(call)', False, 'from mypy.nodes import TypeDef, Node, FuncDef, VarDef, Block, Var, ExpressionStmt, TypeInfo, SuperExpr, NameExpr, CallExpr, MDEF, MemberExpr, ReturnStmt, AssignmentStmt, TypeExpr, PassStmt, SymbolTableNode\n'), ((650, 12, 650, 21), 'mypy.nodes.Var', 'Var', ({(650, 16, 650, 20): 'name'}, {}), '(name)', False, 'from mypy.nodes import TypeDef, Node, FuncDef, VarDef, Block, Var, ExpressionStmt, TypeInfo, SuperExpr, NameExpr, CallExpr, MDEF, MemberExpr, ReturnStmt, AssignmentStmt, TypeExpr, PassStmt, SymbolTableNode\n'), ((656, 16, 656, 30), 'mypy.nodes.NameExpr', 'NameExpr', ({(656, 25, 656, 29): 'name'}, {}), '(name)', False, 'from mypy.nodes import TypeDef, Node, FuncDef, VarDef, Block, Var, ExpressionStmt, TypeInfo, SuperExpr, NameExpr, CallExpr, MDEF, MemberExpr, ReturnStmt, AssignmentStmt, TypeExpr, PassStmt, SymbolTableNode\n'), ((154, 23, 154, 38), 'mypy.semanal.self_type', 'self_type', ({(154, 33, 154, 37): 'info'}, {}), '(info)', False, 'from mypy.semanal import self_type\n'), ((175, 26, 175, 62), 'mypy.transutil.prepend_arg_type', 'prepend_arg_type', ({(175, 43, 175, 54): 'callee_type', (175, 56, 175, 61): 'selft'}, {}), '(callee_type, selft)', False, 'from mypy.transutil import self_expr, tvar_slot_name, tvar_arg_name, prepend_arg_type\n'), ((183, 42, 184, 73), 'mypy.nodes.SymbolTableNode', 'SymbolTableNode', (), '', False, 'from mypy.nodes import TypeDef, Node, FuncDef, VarDef, Block, Var, ExpressionStmt, TypeInfo, SuperExpr, NameExpr, CallExpr, MDEF, MemberExpr, ReturnStmt, AssignmentStmt, TypeExpr, PassStmt, SymbolTableNode\n'), ((241, 33, 241, 67), 'mypy.nodes.method_callable', 'nodes.method_callable', ({(241, 55, 241, 66): 'callee_type'}, {}), '(callee_type)', False, 'from mypy import nodes\n'), ((270, 16, 270, 25), 'mypy.types.AnyType', 'AnyType', ({}, {}), '()', False, 'from mypy.types import Callable, Instance, Type, AnyType, BOUND_VAR, Void, RuntimeTypeVar, UnboundType\n'), ((297, 23, 297, 35), 'mypy.nodes.Block', 'Block', ({(297, 29, 297, 34): '[ret]'}, {}), '([ret])', False, 'from mypy.nodes import TypeDef, Node, FuncDef, VarDef, Block, Var, ExpressionStmt, TypeInfo, SuperExpr, NameExpr, CallExpr, MDEF, MemberExpr, ReturnStmt, AssignmentStmt, TypeExpr, PassStmt, SymbolTableNode\n'), ((314, 42, 314, 51), 'mypy.types.AnyType', 'AnyType', ({}, {}), '()', False, 'from mypy.types import Callable, Instance, Type, AnyType, BOUND_VAR, Void, RuntimeTypeVar, UnboundType\n'), ((319, 57, 319, 66), 'mypy.types.AnyType', 'AnyType', ({}, {}), '()', False, 'from mypy.types import Callable, Instance, Type, AnyType, BOUND_VAR, Void, RuntimeTypeVar, UnboundType\n'), ((324, 23, 324, 35), 'mypy.nodes.Block', 'Block', ({(324, 29, 324, 34): '[ret]'}, {}), '([ret])', False, 'from mypy.nodes import TypeDef, Node, FuncDef, VarDef, Block, Var, ExpressionStmt, TypeInfo, SuperExpr, NameExpr, CallExpr, MDEF, MemberExpr, ReturnStmt, AssignmentStmt, TypeExpr, PassStmt, SymbolTableNode\n'), ((347, 23, 347, 29), 'mypy.types.Void', 'Void', ({}, {}), '()', False, 'from mypy.types import Callable, Instance, Type, AnyType, BOUND_VAR, Void, RuntimeTypeVar, UnboundType\n'), ((352, 23, 352, 35), 'mypy.nodes.Block', 'Block', ({(352, 29, 352, 34): '[ret]'}, {}), '([ret])', False, 'from mypy.nodes import TypeDef, Node, FuncDef, VarDef, Block, Var, ExpressionStmt, TypeInfo, SuperExpr, NameExpr, CallExpr, MDEF, MemberExpr, ReturnStmt, AssignmentStmt, TypeExpr, PassStmt, SymbolTableNode\n'), ((364, 28, 364, 39), 'mypy.transutil.self_expr', 'self_expr', ({}, {}), '()', False, 'from mypy.transutil import self_expr, tvar_slot_name, tvar_arg_name, prepend_arg_type\n'), ((366, 40, 366, 49), 'mypy.types.AnyType', 'AnyType', ({}, {}), '()', False, 'from mypy.types import Callable, Instance, Type, AnyType, BOUND_VAR, Void, RuntimeTypeVar, UnboundType\n'), ((374, 23, 374, 29), 'mypy.types.Void', 'Void', ({}, {}), '()', False, 'from mypy.types import Callable, Instance, Type, AnyType, BOUND_VAR, Void, RuntimeTypeVar, UnboundType\n'), ((379, 23, 379, 35), 'mypy.nodes.Block', 'Block', ({(379, 29, 379, 34): '[ret]'}, {}), '([ret])', False, 'from mypy.nodes import TypeDef, Node, FuncDef, VarDef, Block, Var, ExpressionStmt, TypeInfo, SuperExpr, NameExpr, CallExpr, MDEF, MemberExpr, ReturnStmt, AssignmentStmt, TypeExpr, PassStmt, SymbolTableNode\n'), ((436, 26, 436, 37), 'mypy.nodes.Block', 'Block', ({(436, 32, 436, 36): 'defs'}, {}), '(defs)', False, 'from mypy.nodes import TypeDef, Node, FuncDef, VarDef, Block, Var, ExpressionStmt, TypeInfo, SuperExpr, NameExpr, CallExpr, MDEF, MemberExpr, ReturnStmt, AssignmentStmt, TypeExpr, PassStmt, SymbolTableNode\n'), ((478, 16, 478, 37), 'mypy.nodes.SuperExpr', 'SuperExpr', ({(478, 26, 478, 36): '"""__init__"""'}, {}), "('__init__')", False, 'from mypy.nodes import TypeDef, Node, FuncDef, VarDef, Block, Var, ExpressionStmt, TypeInfo, SuperExpr, NameExpr, CallExpr, MDEF, MemberExpr, ReturnStmt, AssignmentStmt, TypeExpr, PassStmt, SymbolTableNode\n'), ((495, 16, 495, 27), 'mypy.nodes.Var', 'Var', ({(495, 20, 495, 26): '"""self"""'}, {}), "('self')", False, 'from mypy.nodes import TypeDef, Node, FuncDef, VarDef, Block, Var, ExpressionStmt, TypeInfo, SuperExpr, NameExpr, CallExpr, MDEF, MemberExpr, ReturnStmt, AssignmentStmt, TypeExpr, PassStmt, SymbolTableNode\n'), ((495, 29, 495, 39), 'mypy.nodes.Var', 'Var', ({(495, 33, 495, 38): '"""__o"""'}, {}), "('__o')", False, 'from mypy.nodes import TypeDef, Node, FuncDef, VarDef, Block, Var, ExpressionStmt, TypeInfo, SuperExpr, NameExpr, CallExpr, MDEF, MemberExpr, ReturnStmt, AssignmentStmt, TypeExpr, PassStmt, SymbolTableNode\n'), ((508, 23, 508, 35), 'mypy.nodes.Block', 'Block', ({(508, 29, 508, 34): 'cdefs'}, {}), '(cdefs)', False, 'from mypy.nodes import TypeDef, Node, FuncDef, VarDef, Block, Var, ExpressionStmt, TypeInfo, SuperExpr, NameExpr, CallExpr, MDEF, MemberExpr, ReturnStmt, AssignmentStmt, TypeExpr, PassStmt, SymbolTableNode\n'), ((541, 23, 541, 44), 'mypy.maptypevar.num_slots', 'num_slots', ({(541, 33, 541, 43): 'creat.info'}, {}), '(creat.info)', False, 'from mypy.maptypevar import num_slots, get_tvar_access_path\n'), ((607, 34, 607, 67), 'mypy.checkexpr.type_object_type', 'type_object_type', ({(607, 51, 607, 60): 'tdef.info', (607, 62, 607, 66): 'None'}, {}), '(tdef.info, None)', False, 'from mypy.checkexpr import type_object_type\n'), ((608, 34, 608, 68), 'mypy.erasetype.erase_typevars', 'erasetype.erase_typevars', ({(608, 59, 608, 67): 'type_sig'}, {}), '(type_sig)', False, 'from mypy import erasetype\n'), ((616, 31, 616, 40), 'mypy.types.AnyType', 'AnyType', ({}, {}), '()', False, 'from mypy.types import Callable, Instance, Type, AnyType, BOUND_VAR, Void, RuntimeTypeVar, UnboundType\n'), ((631, 23, 631, 35), 'mypy.nodes.Block', 'Block', ({(631, 29, 631, 34): '[ret]'}, {}), '([ret])', False, 'from mypy.nodes import TypeDef, Node, FuncDef, VarDef, Block, Var, ExpressionStmt, TypeInfo, SuperExpr, NameExpr, CallExpr, MDEF, MemberExpr, ReturnStmt, AssignmentStmt, TypeExpr, PassStmt, SymbolTableNode\n'), ((92, 20, 92, 40), 'typing.cast', 'cast', ({(92, 25, 92, 28): 'Var', (92, 30, 92, 39): 'node.node'}, {}), '(Var, node.node)', False, 'from typing import Undefined, List, Set, Any, cast, Tuple, Dict\n'), ((105, 24, 105, 34), 'mypy.nodes.PassStmt', 'PassStmt', ({}, {}), '()', False, 'from mypy.nodes import TypeDef, Node, FuncDef, VarDef, Block, Var, ExpressionStmt, TypeInfo, SuperExpr, NameExpr, CallExpr, MDEF, MemberExpr, ReturnStmt, AssignmentStmt, TypeExpr, PassStmt, SymbolTableNode\n'), ((155, 41, 157, 21), 'mypy.checkmember.analyse_member_access', 'analyse_member_access', ({(156, 16, 156, 26): '"""__init__"""', (156, 28, 156, 36): 'selftype', (156, 38, 156, 42): 'None', (156, 44, 156, 49): 'False', (156, 51, 156, 55): 'True', (156, 57, 156, 61): 'None', (156, 63, 156, 67): 'None', (157, 16, 157, 20): 'base'}, {}), "('__init__', selftype, None, False, True, None, None, base\n    )", False, 'from mypy.checkmember import analyse_member_access\n'), ((164, 16, 164, 57), 'mypy.subtypes.map_instance_to_supertype', 'map_instance_to_supertype', ({(164, 42, 164, 50): 'selftype', (164, 52, 164, 56): 'base'}, {}), '(selftype, base)', False, 'from mypy.subtypes import map_instance_to_supertype\n'), ((169, 20, 169, 31), 'mypy.nodes.Var', 'Var', ({(169, 24, 169, 30): '"""self"""'}, {}), "('self')", False, 'from mypy.nodes import TypeDef, Node, FuncDef, VarDef, Block, Var, ExpressionStmt, TypeInfo, SuperExpr, NameExpr, CallExpr, MDEF, MemberExpr, ReturnStmt, AssignmentStmt, TypeExpr, PassStmt, SymbolTableNode\n'), ((179, 28, 179, 37), 'mypy.nodes.Block', 'Block', ({(179, 34, 179, 36): '[]'}, {}), '([])', False, 'from mypy.nodes import TypeDef, Node, FuncDef, VarDef, Block, Var, ExpressionStmt, TypeInfo, SuperExpr, NameExpr, CallExpr, MDEF, MemberExpr, ReturnStmt, AssignmentStmt, TypeExpr, PassStmt, SymbolTableNode\n'), ((371, 31, 371, 40), 'mypy.types.AnyType', 'AnyType', ({}, {}), '()', False, 'from mypy.types import Callable, Instance, Type, AnyType, BOUND_VAR, Void, RuntimeTypeVar, UnboundType\n'), ((376, 24, 376, 35), 'mypy.nodes.Var', 'Var', ({(376, 28, 376, 34): '"""self"""'}, {}), "('self')", False, 'from mypy.nodes import TypeDef, Node, FuncDef, VarDef, Block, Var, ExpressionStmt, TypeInfo, SuperExpr, NameExpr, CallExpr, MDEF, MemberExpr, ReturnStmt, AssignmentStmt, TypeExpr, PassStmt, SymbolTableNode\n'), ((376, 37, 376, 46), 'mypy.nodes.Var', 'Var', ({(376, 41, 376, 45): 'name'}, {}), '(name)', False, 'from mypy.nodes import TypeDef, Node, FuncDef, VarDef, Block, Var, ExpressionStmt, TypeInfo, SuperExpr, NameExpr, CallExpr, MDEF, MemberExpr, ReturnStmt, AssignmentStmt, TypeExpr, PassStmt, SymbolTableNode\n'), ((479, 21, 479, 36), 'mypy.nodes.NameExpr', 'NameExpr', ({(479, 30, 479, 35): '"""__o"""'}, {}), "('__o')", False, 'from mypy.nodes import TypeDef, Node, FuncDef, VarDef, Block, Var, ExpressionStmt, TypeInfo, SuperExpr, NameExpr, CallExpr, MDEF, MemberExpr, ReturnStmt, AssignmentStmt, TypeExpr, PassStmt, SymbolTableNode\n'), ((480, 27, 480, 42), 'mypy.maptypevar.num_slots', 'num_slots', ({(480, 37, 480, 41): 'base'}, {}), '(base)', False, 'from mypy.maptypevar import num_slots, get_tvar_access_path\n'), ((482, 27, 482, 42), 'mypy.maptypevar.num_slots', 'num_slots', ({(482, 37, 482, 41): 'base'}, {}), '(base)', False, 'from mypy.maptypevar import num_slots, get_tvar_access_path\n'), ((485, 25, 485, 42), 'mypy.nodes.ExpressionStmt', 'ExpressionStmt', ({(485, 40, 485, 41): 'c'}, {}), '(c)', False, 'from mypy.nodes import TypeDef, Node, FuncDef, VarDef, Block, Var, ExpressionStmt, TypeInfo, SuperExpr, NameExpr, CallExpr, MDEF, MemberExpr, ReturnStmt, AssignmentStmt, TypeExpr, PassStmt, SymbolTableNode\n'), ((492, 36, 492, 51), 'mypy.nodes.NameExpr', 'NameExpr', ({(492, 45, 492, 50): '"""__o"""'}, {}), "('__o')", False, 'from mypy.nodes import TypeDef, Node, FuncDef, VarDef, Block, Var, ExpressionStmt, TypeInfo, SuperExpr, NameExpr, CallExpr, MDEF, MemberExpr, ReturnStmt, AssignmentStmt, TypeExpr, PassStmt, SymbolTableNode\n'), ((511, 32, 511, 38), 'mypy.types.Void', 'Void', ({}, {}), '()', False, 'from mypy.types import Callable, Instance, Type, AnyType, BOUND_VAR, Void, RuntimeTypeVar, UnboundType\n'), ((547, 46, 547, 55), 'mypy.types.AnyType', 'AnyType', ({}, {}), '()', False, 'from mypy.types import Callable, Instance, Type, AnyType, BOUND_VAR, Void, RuntimeTypeVar, UnboundType\n'), ((548, 42, 548, 51), 'mypy.types.AnyType', 'AnyType', ({}, {}), '()', False, 'from mypy.types import Callable, Instance, Type, AnyType, BOUND_VAR, Void, RuntimeTypeVar, UnboundType\n'), ((558, 27, 558, 48), 'mypy.maptypevar.num_slots', 'num_slots', ({(558, 37, 558, 47): 'creat.info'}, {}), '(creat.info)', False, 'from mypy.maptypevar import num_slots, get_tvar_access_path\n'), ((530, 19, 530, 52), 'mypy.maptypevar.get_tvar_access_path', 'get_tvar_access_path', ({(530, 40, 530, 44): 'info', (530, 46, 530, 51): '(n + 1)'}, {}), '(info, n + 1)', False, 'from mypy.maptypevar import num_slots, get_tvar_access_path\n'), ((565, 50, 565, 59), 'mypy.types.AnyType', 'AnyType', ({}, {}), '()', False, 'from mypy.types import Callable, Instance, Type, AnyType, BOUND_VAR, Void, RuntimeTypeVar, UnboundType\n'), ((566, 46, 566, 55), 'mypy.types.AnyType', 'AnyType', ({}, {}), '()', False, 'from mypy.types import Callable, Instance, Type, AnyType, BOUND_VAR, Void, RuntimeTypeVar, UnboundType\n'), ((614, 33, 614, 42), 'mypy.types.AnyType', 'AnyType', ({}, {}), '()', False, 'from mypy.types import Callable, Instance, Type, AnyType, BOUND_VAR, Void, RuntimeTypeVar, UnboundType\n'), ((461, 28, 461, 37), 'mypy.types.AnyType', 'AnyType', ({}, {}), '()', False, 'from mypy.types import Callable, Instance, Type, AnyType, BOUND_VAR, Void, RuntimeTypeVar, UnboundType\n'), ((481, 38, 481, 58), 'mypy.transutil.tvar_arg_name', 'tvar_arg_name', ({(481, 52, 481, 57): '(n + 1)'}, {}), '(n + 1)', False, 'from mypy.transutil import self_expr, tvar_slot_name, tvar_arg_name, prepend_arg_type\n'), ((483, 38, 483, 69), 'mypy.transutil.tvar_arg_name', 'tvar_arg_name', ({(483, 52, 483, 57): '(n + 1)', (483, 59, 483, 68): 'BOUND_VAR'}, {}), '(n + 1, BOUND_VAR)', False, 'from mypy.transutil import self_expr, tvar_slot_name, tvar_arg_name, prepend_arg_type\n'), ((489, 41, 489, 52), 'mypy.transutil.self_expr', 'self_expr', ({}, {}), '()', False, 'from mypy.transutil import self_expr, tvar_slot_name, tvar_arg_name, prepend_arg_type\n'), ((500, 32, 500, 57), 'mypy.transutil.tvar_arg_name', 'tvar_arg_name', ({(500, 46, 500, 51): '(n + 1)', (500, 53, 500, 56): 'alt'}, {}), '(n + 1, alt)', False, 'from mypy.transutil import self_expr, tvar_slot_name, tvar_arg_name, prepend_arg_type\n'), ((509, 34, 509, 43), 'mypy.types.AnyType', 'AnyType', ({}, {}), '()', False, 'from mypy.types import Callable, Instance, Type, AnyType, BOUND_VAR, Void, RuntimeTypeVar, UnboundType\n'), ((543, 46, 543, 57), 'mypy.transutil.self_expr', 'self_expr', ({}, {}), '()', False, 'from mypy.transutil import self_expr, tvar_slot_name, tvar_arg_name, prepend_arg_type\n'), ((544, 46, 544, 63), 'mypy.transutil.tvar_slot_name', 'tvar_slot_name', ({(544, 61, 544, 62): 'n'}, {}), '(n)', False, 'from mypy.transutil import self_expr, tvar_slot_name, tvar_arg_name, prepend_arg_type\n'), ((560, 44, 560, 66), 'mypy.transutil.tvar_slot_name', 'tvar_slot_name', ({(560, 59, 560, 60): 'n', (560, 62, 560, 65): 'alt'}, {}), '(n, alt)', False, 'from mypy.transutil import self_expr, tvar_slot_name, tvar_arg_name, prepend_arg_type\n'), ((562, 32, 562, 43), 'mypy.transutil.self_expr', 'self_expr', ({}, {}), '()', False, 'from mypy.transutil import self_expr, tvar_slot_name, tvar_arg_name, prepend_arg_type\n'), ((563, 32, 563, 54), 'mypy.transutil.tvar_slot_name', 'tvar_slot_name', ({(563, 47, 563, 48): 'n', (563, 50, 563, 53): 'alt'}, {}), '(n, alt)', False, 'from mypy.transutil import self_expr, tvar_slot_name, tvar_arg_name, prepend_arg_type\n'), ((532, 40, 532, 68), 'mypy.transutil.tvar_slot_name', 'tvar_slot_name', ({(532, 55, 532, 59): 'slot', (532, 61, 532, 67): 'is_alt'}, {}), '(slot, is_alt)', False, 'from mypy.transutil import self_expr, tvar_slot_name, tvar_arg_name, prepend_arg_type\n'), ((533, 40, 533, 49), 'mypy.types.AnyType', 'AnyType', ({}, {}), '()', False, 'from mypy.types import Callable, Instance, Type, AnyType, BOUND_VAR, Void, RuntimeTypeVar, UnboundType\n')]