Skip to main content

ModelPrivateAttr

A descriptor for private attributes in class models.

Attributes

AttributeTypeDescription
defaultAny = PydanticUndefinedThe default value of the attribute if not provided.
default_factory`Callable[[], Any]Callable[[dict[str, Any]], Any]

Constructor

Signature

def ModelPrivateAttr(
default: Any = PydanticUndefined,
default_factory: Callable[[], Any]| Callable[[dict[str, Any]], Any]| None = None
) - > None

Parameters

NameTypeDescription
defaultAny = PydanticUndefinedThe default value of the attribute. If Ellipsis is provided, it is treated as PydanticUndefined.
default_factory`Callable[[], Any]Callable[[dict[str, Any]], Any]

Signature

def ModelPrivateAttr(
default: Any = PydanticUndefined,
default_factory: Callable | None = None
) - > None

Parameters

NameTypeDescription
defaultAny = PydanticUndefinedThe static default value to assign to the private attribute; Ellipsis is treated as undefined.
default_factory`CallableNone` = None

Methods


default_factory_takes_validated_data()

@classmethod
def default_factory_takes_validated_data() - > bool | None

Whether the provided default factory callable has a validated data parameter.

Returns

TypeDescription
`boolNone`

get_default()

@classmethod
def get_default(
call_default_factory: bool = False,
validated_data: dict[str, Any]| None = None
) - > Any

Get the default value.

Parameters

NameTypeDescription
call_default_factorybool = FalseWhether to call the default factory or not.
validated_data`dict[str, Any]None` = None

Returns

TypeDescription
AnyThe default value, calling the default factory if requested or None if not set.