Source code for cadrumo.domain.calculations.registry._toml_helpers
"""Shared TOML-table narrowing helper for the registry loader family.Kept as the single narrowing helper used by the registry compiler family."""from__future__importannotationsfromtypingimportcast
[docs]defas_toml_table(value:object)->dict[str,object]|None:"""Narrow a parsed TOML value to a string-keyed table, or ``None``. The original dictionary identity is preserved and every key is validated before the deserialization-boundary type is restored. """ifnotisinstance(value,dict):returnNone# CAST-RATIONALE-TOML-TABLE-KEY-ITERATION: isinstance narrows to dict but# not its type parameters; each key is validated as str in the loop below.# nosemgrep: no-cast-in-domain-applicationforkeyincast("dict[object, object]",value):ifnotisinstance(key,str):returnNone# CAST-RATIONALE-TOML-VALIDATED-KEYS-PRESERVE-IDENTITY: every key is# runtime-validated as str, but a cast is required to retain the original# dict identity used by in-place locale merging.returncast(# nosemgrep: no-cast-in-domain-application reason: validated table identity must survive merging."dict[str, object]",value,)