httk.core.views.coercion¶
General best-effort coercion into registered view or value classes.
Attributes¶
Functions¶
|
Append |
|
Return a coercer that tries matching view classes in |
|
Coerce |
Module Contents¶
- httk.core.views.coercion.register_coercer(coercer: Coercer) None[source]¶
Append
coercerto the registry, preserving registration order.
- httk.core.views.coercion.view_class_coercer(view_classes: collections.abc.Sequence[type]) Coercer[source]¶
Return a coercer that tries matching view classes in
view_classesorder.A
TypeError,ValueError, orOverflowErrorfrom a view constructor means that view cannot represent the value, so construction continues with the next matching class. If a candidate exposes_ensure_materialized(), explicit coercion calls it so lazy views are materialized and deferred data errors follow the same fall-through contract.
- httk.core.views.coercion.coerce(value: Any, target: Any) Any[source]¶
Coerce
valueto a target class or prototype instance.The exact string
"natural"is a documented sentinel that returnsvalueunchanged. Otherwise, a class target is used directly and an instance target is treated as a prototype, using its type. Values already matching the target are returned unchanged. Registered coercers are then tried in registration order, and the first non-Noneresult wins. If none succeeds,TypeErroris raised naming the value type and target. Coercion is best effort and favors lossless view wrapping; individual coercers document any deliberately lossy conversion.