ModelPrivateAttr
A descriptor for private attributes in class models.
Attributes
| Attribute | Type | Description |
|---|---|---|
| default | Any = PydanticUndefined | The 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
| Name | Type | Description |
|---|---|---|
| default | Any = PydanticUndefined | The 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
| Name | Type | Description |
|---|---|---|
| default | Any = PydanticUndefined | The static default value to assign to the private attribute; Ellipsis is treated as undefined. |
| default_factory | `Callable | None` = 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
| Type | Description |
|---|---|
| `bool | None` |
get_default()
@classmethod
def get_default(
call_default_factory: bool = False,
validated_data: dict[str, Any]| None = None
) - > Any
Get the default value.
Parameters
| Name | Type | Description |
|---|---|---|
| call_default_factory | bool = False | Whether to call the default factory or not. |
| validated_data | `dict[str, Any] | None` = None |
Returns
| Type | Description |
|---|---|
Any | The default value, calling the default factory if requested or None if not set. |