Skip to content

treex.ToDict

Mixin that adds a .to_dict() method to the class.

to_dict(self, *, private_fields=False, static_fields=True, type_info=False, field_info=False)

to_dict is a wrapper over treeo.to_dict that passes self as the first argument.

Parameters:

Name Type Description Default
private_fields bool

If True, private fields are included.

False
static_fields bool

If True, static fields are included.

True
type_info bool

If True, type information is included.

False
field_info bool

If True, field information is included.

False

Returns:

Type Description
Any

A dict representation of the object.

Source code in treeo/mixins.py
def to_dict(
    self,
    *,
    private_fields: bool = False,
    static_fields: bool = True,
    type_info: bool = False,
    field_info: bool = False,
) -> tp.Any:
    """
    `to_dict` is a wrapper over `treeo.to_dict` that passes `self` as the first argument.

    Arguments:
        private_fields: If `True`, private fields are included.
        static_fields: If `True`, static fields are included.
        type_info: If `True`, type information is included.
        field_info: If `True`, field information is included.

    Returns:
        A dict representation of the object.
    """
    return api.to_dict(
        self,
        private_fields=private_fields,
        static_fields=static_fields,
        type_info=type_info,
        field_info=field_info,
    )