Source code for cadrumo.application.calculations._per_grupo_member_keys
"""Shared derivation of the ``per_grupo_member`` cross-member fan-in keys.A ``previous_filing`` binding whose selector declares``grouping = "per_grupo_member"`` (the 353<-322 cross-member aggregation) issatisfied by EVERY grupo member's filing for a``(modelo, filing_year, period)`` key, not by a single filer's. Both thebinding-prefill gatherer(:mod:`~application.calculations.binding_prefill`, which must enumerate themembers rather than load one observation by key) and the cross-periodclean-state gate(:mod:`~application.calculations.cross_period_clean_state`, which must mark therequirement ``requires_member_fan_in``) need the same key set, so it is derivedonce here.Sister shared module to :mod:`~.revision_carry_gate`."""from__future__importannotationsfrom...domain.calculations.registry.bindings_previous_filingimport(PreviousFilingProvider,previous_filing_observation_requirements,)from...domain.calculations.registry.schemaimportModeloRevision_PER_GRUPO_MEMBER:str="per_grupo_member"
[docs]defper_grupo_member_requirement_keys(revision:ModeloRevision,*,filing_year:int,period:str,)->set[tuple[str,int,str]]:"""Return the ``(modelo, filing_year, period)`` keys whose binding declares ``per_grupo_member``. A structural fold over the revision's declared bindings and the law-determined filing coordinate; it never reads validated evidence, so it takes the compiled :class:`ModeloRevision` directly rather than a filing-grade :class:`~cadrumo.domain.calculations.registry.schema.RegistrySnapshot`. Args: revision: The :class:`ModeloRevision` whose bindings are scanned for a ``previous_filing`` selector declaring ``grouping = "per_grupo_member"``. filing_year: The filing coordinate's year. period: The filing coordinate's period token. """grouped_binding_ids={binding.idforbindinginrevision.bindingsifisinstance(binding.provider,PreviousFilingProvider)andbinding.provider.grouping==_PER_GRUPO_MEMBER}ifnotgrouped_binding_ids:returnset()keys:set[tuple[str,int,str]]=set()forrequirementinprevious_filing_observation_requirements(revision,filing_year=filing_year,period=period,):ifany(binding_idingrouped_binding_idsforbinding_idinrequirement.binding_ids):keys.add((requirement.source_modelo,requirement.filing_year,requirement.periods[0]))returnkeys