Пример #1
0
 def make_generic_wrapper_member_vars(self, tdef: ClassDef) -> 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)]
Пример #2
0
    def visit_var_def(self, o: VarDef) -> None:
        """Transform a variable definition in-place.

        This is not suitable for member variable definitions; they are
        transformed in TypeTransformer.
        """
        super().visit_var_def(o)

        if o.init is not None:
            if o.items[0].type:
                t = o.items[0].type
            else:
                t = AnyType()
            o.init = self.coerce(o.init, t, self.get_type(o.init), self.type_context())
Пример #3
0
    def visit_var_def(self, o: VarDef) -> None:
        """Transform a variable definition in-place.

        This is not suitable for member variable definitions; they are
        transformed in TypeTransformer.
        """
        super().visit_var_def(o)

        if o.init is not None:
            if o.items[0].type:
                t = o.items[0].type
            else:
                t = AnyType()
            o.init = self.coerce(o.init, t, self.get_type(o.init),
                                 self.type_context())
Пример #4
0
    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
Пример #5
0
 def visit_var_def(self, node: VarDef) -> Node:
     new = VarDef([self.visit_var(var) for var in node.items],
                  node.is_top_level, self.optional_node(node.init))
     new.kind = node.kind
     return new
Пример #6
0
 def visit_var_def(self, node: VarDef) -> Node:
     new = VarDef([self.visit_var(var) for var in node.items],
                  node.is_top_level,
                  self.optional_node(node.init))
     new.kind = node.kind
     return new