gallium.obj.builder

This module provides an object builder inspired by Lombok (Java).

Quick start

Here is a quick example on how to use it.

@dataclass
class User:
    name: str
    age: int

ObjectBuilder(User).name("Foo").age(123).build()

Note

This is tested with Python’s built-in dataclass and Pylandic’s BaseModel.

class gallium.obj.builder.Attribute(spec: gallium.obj.builder.AttributeSpec, value: Any, initialized: bool)

Class Attribute

class gallium.obj.builder.AttributeSpec(name: str, types: Tuple[Type], optional: bool, default: Any)

Class Attribute Specification

exception gallium.obj.builder.IncompatibleBuildableClassError

Class annotations does not exist

class gallium.obj.builder.ObjectBuilder(cls: Type)

Object Builder

Inspired by the lombok.builder annotation. (Java)

build(define_all_attributes: bool = True)

Build an instance of the given class

Parameters

define_all_attributes (bool) – Flag to whether to fill in all attributes, including the ones which are not covered by the constructor.

exception gallium.obj.builder.RequiredAttributeError

Attribute in question is not defined before building the object