Ejemplo n.º 1
0
    def dataclass_non_ext_info(self, cdef: ClassDef) -> Optional[NonExtClassInfo]:
        """Set up a NonExtClassInfo to track dataclass attributes.

        In addition to setting up a normal extension class for dataclasses,
        we also collect its class attributes like a non-extension class so
        that we can hand them to the dataclass decorator.
        """
        if is_dataclass(cdef):
            return NonExtClassInfo(
                self.primitive_op(new_dict_op, [], cdef.line),
                self.add(TupleSet([], cdef.line)),
                self.primitive_op(new_dict_op, [], cdef.line),
                self.primitive_op(type_object_op, [], cdef.line),
            )
        else:
            return None
Ejemplo n.º 2
0
def transform_tuple_expr(builder: IRBuilder, expr: TupleExpr) -> Value:
    if any(isinstance(item, StarExpr) for item in expr.items):
        # create a tuple of unknown length
        return _visit_tuple_display(builder, expr)

    # create a tuple of fixed length (RTuple)
    tuple_type = builder.node_type(expr)
    # When handling NamedTuple et. al we might not have proper type info,
    # so make some up if we need it.
    types = (tuple_type.types if isinstance(tuple_type, RTuple) else
             [object_rprimitive] * len(expr.items))

    items = []
    for item_expr, item_type in zip(expr.items, types):
        reg = builder.accept(item_expr)
        items.append(builder.coerce(reg, item_type, item_expr.line))
    return builder.add(TupleSet(items, expr.line))