Skip to content

Commit ef2fde6

Browse files
author
Wojtek
committed
load_all documentation
1 parent ad98587 commit ef2fde6

1 file changed

Lines changed: 56 additions & 0 deletions

File tree

dbzero/dbzero/dbzero.pyi

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,62 @@ def load(obj: Any, /, *, exclude: Optional[Union[List[str], Tuple[str, ...]]] =
332332
"""
333333
...
334334

335+
336+
def load_all(obj: Any, /, *, exclude: Optional[Union[List[str], Tuple[str, ...]]] = None, **kwargs: Any) -> Any:
337+
"""Load a dbzero instance recursively into memory, ignoring the top-level custom __load__ method.
338+
339+
It works similarly to load() but ignores custom __load__ implementations
340+
for the top-level object. This is useful for implementing custom __load__ methods where
341+
we want to retrieve all fields along with additional data (e.g., all fields + UUID).
342+
343+
Parameters
344+
----------
345+
obj : Any
346+
The object to convert. Can be native Python type, dbzero object,
347+
or @dbzero.memo class instance.
348+
exclude : list of str or tuple of str, optional
349+
Optional list of attribute names to exclude when loading
350+
@dbzero.memo class instances. Only works with default serialization.
351+
**kwargs : dict
352+
Additional keyword arguments passed to custom __load__ methods.
353+
354+
Returns
355+
-------
356+
Any
357+
Converted object with the following behavior:
358+
359+
* Native types: Returned as-is
360+
* dbzero collections: Converted to built-in counterparts (list, tuple, set, dict)
361+
* @dbzero.enum values: Converted to string representation
362+
* @dbzero.memo instances: Converted to dictionaries (or using custom __load__ method)
363+
364+
Raises
365+
------
366+
RecursionError
367+
If the object contains cyclic references.
368+
AttributeError
369+
If exclude is used with custom __load__ methods.
370+
371+
Examples
372+
--------
373+
Loading all fields + UUID:
374+
375+
>>> @db0.memo
376+
... @dataclass
377+
... class User:
378+
... first_name: str
379+
... last_name: str
380+
... email: str
381+
...
382+
... def __load__(self):
383+
... return {
384+
... "uuid": db0..uuid(self),
385+
... **db0.load_all(self)
386+
... }
387+
"""
388+
...
389+
390+
335391
def hash(obj: Any, /) -> int:
336392
"""Compute a deterministic 64-bit integer hash for any object.
337393

0 commit comments

Comments
 (0)