Mojo struct
PyMojoObject
struct PyMojoObject[T: AnyType]
Storage backing a PyObject* wrapping a Mojo value.
This struct represents the C-level layout of a Python object that contains a wrapped Mojo value. It must be ABI-compatible with CPython's PyObject structure to enable seamless interoperability between Mojo and Python.
The struct follows Python's object model where all Python objects begin with a PyObject header (ob_base), followed by type-specific data. In this case, the type-specific data is a Mojo value of type T.
See https://docs.python.org/3/c-api/structures.html#c.PyObject for more details.
Parameters
- T (
AnyType
): The Mojo type being wrapped. Can be any type that satisfiesAnyType
.
Fields
- ob_base (
PyObject
): The standard Python object header containing reference count and type information. This must be the first field to maintain ABI compatibility with Python's object layout. All Python objects begin with this header structure. - mojo_value (
T
): The actual Mojo value being wrapped and exposed to Python. This field stores the Mojo data that Python code can interact with through the registered type methods and bindings.
Implemented traits
AnyType
,
UnknownDestructibility
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!