confit.draft
MetaDraft [source]
Bases: type
A metaclass for Draft that allows the user to create specify the type the Draft should become when instantiated.
In addition to allowing static typing, this metaclass also provides a way to validate the Draft object when used in combination with pydantic validation.
Examples
from confit import Draft
@validate_arguments
def make_hi(name, prefix) -> str:
return prefix + " " + name
@validate_arguments
def print_hi(param: Draft[str]):
val = param.instantiate(prefix="Hello")
print(val)
print_hi(make_hi.draft(name="John"))
Source code in confit/draft.py
82 83 84 | |
Draft [source]
Bases: Generic[R]
A Draft is a placeholder for a value that has not been instantiated yet, likely because it is missing an argument that will be provided later by the library.
Source code in confit/draft.py
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | |
instantiate [source]
Finalize the Draft object into an instance of the expected type using the provided arguments. The new arguments are merged with the existing ones, with the old ones taking precedence. The rationale for this is that the user makes the Draft, and the library completes any missing arguments.
Source code in confit/draft.py
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |