Source code for aeat.domain.calculations.registry._toml_helpers
"""Shared TOML-table narrowing helper for the registry loader family.Extracted so both :mod:`~domain.calculations.registry._loader` and:mod:`~domain.calculations.registry._loader_locales` can narrow a parsedTOML value to a string-keyed table without importing each other (avoiding aruntime import cycle between the compiler and the locale-merge submodule)."""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``. ``tomllib`` and :func:`~core.freeze_toml` always emit ``str`` keys, so a parsed-TOML ``dict`` is genuinely ``dict[str, object]``. The runtime ``isinstance`` check loses the key type because TOML payloads flow through ``object``; the annotation below re-attaches the known ``str`` key type at this single TOML deserialization boundary. """ifisinstance(value,dict):# CAST-RATIONALE-TOML-STR-KEY-ERASURE: tomllib/freeze_toml always# produces str-keyed dicts; isinstance loses the key type annotation.returncast("dict[str, object]",value)returnNone