You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`FlatInitModel` also handles model union types by processing the first model type of the union.
142
+
143
+
A common use case for model union types is e.g. to assign a default value to a model union typed field in case a nested model instance does not meet certain criteria, i.e. fails a predicate.
144
+
145
+
The `model_bool` parameter in `lupl.ConfigDict` allows to specify the condition for *model truthiness* - if the existential condition of a model is met, the model instance gets assigned to the model field, else the constructor falls back to the default value.
146
+
147
+
148
+
The default condition for model truthiness is that *any* model field must be truthy for the model to be considered truthy.
128
149
150
+
The `model_bool` parameter takes either
129
151
130
-
classComplexModel(BaseModel):
131
-
p: str
132
-
q: NestedModel
152
+
- a callable object of arity 1 that receives the model instance at runtime,
153
+
- a `str` denoting a field of the model that must be truthy in order for the model to be truthy
154
+
- a `set[str]` denoting fields of the model, all of which must be truthy for the model to be truthy.
The following example defines the truth condition for `DeeplyNestedModel` to be `gt3`. `NestedModel` defines a model union type with a default value - if the `model_bool` predicate fails, the constructor falls back to the default:
0 commit comments