Skip to content

Py

PyAttr dataclass

PyAttr(data: T, pytype: TypeAttribute | None = None)

Bases: Data[T]

Python attribute for compile-time values. This is a generic attribute that holds a Python value.

The constructor takes a Python value and an optional type attribute. If the type attribute is not provided, the type of the value is inferred as PyClass(type(value)).

Pretty Printing

This object is pretty printable via .print() method.

Source code in src/kirin/ir/attrs/py.py
29
30
31
32
33
34
35
def __init__(self, data: T, pytype: TypeAttribute | None = None):
    self.data = data

    if pytype is None:
        self.type = PyClass(type(data))
    else:
        self.type = pytype

name class-attribute instance-attribute

name = 'PyAttr'

Name of the attribute in printing and other text format.

unwrap

unwrap() -> T

Returns the underlying data value.

Source code in src/kirin/ir/attrs/py.py
46
47
def unwrap(self) -> T:
    return self.data