| afad | 3.3 | |||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| version | 0.7.0 | |||||||||||||||||||||
| domain | SECONDARY | |||||||||||||||||||||
| updated | 2026-03-18 | |||||||||||||||||||||
| route |
|
Immutable static descriptor for a legislative-pack implementation.
@dataclass(frozen=True, slots=True)
class LegislativePackMetadata:
pack_code: LegislativePackCode
territory_code: TerritoryCode
tax_year: int
default_locale: str
currencies: tuple[CurrencyCode, ...] | list[CurrencyCode]pack_codemust be non-empty.territory_codemust be a valid ISO 3166-1 alpha-2 code viaftllexengine.introspection.is_valid_territory_code().tax_yearmust be anintin1..9999;boolis rejected.default_localeis normalized to the canonical lowercase POSIX locale form viaftllexengine.core.locale_utils.require_locale_code().currenciesmust be non-empty; each element must be a valid ISO 4217 code; stored as tuple.
Immutable structured finding emitted by a legislative pack validation.
@dataclass(frozen=True, slots=True)
class LegislativeIssue:
code: str
message: str
entry_index: int | None = Nonecodeandmessagemust be non-empty strings.entry_index, when present, must be a non-negativeint;boolis rejected.- Identifies which ledger entry triggered the issue, or
Nonefor transaction-level findings.
Immutable container of LegislativeIssue values produced by a pack.
@dataclass(frozen=True, slots=True)
class LegislativeValidationResult:
pack_code: LegislativePackCode
issues: tuple[LegislativeIssue, ...] | list[LegislativeIssue] = ()
@property
def accepted(self) -> bool: ...
def require_valid(self) -> None: ...pack_codemust be non-empty;issuesare stored as tuple.accepted:Truewhenissuesis empty.require_valid: raisesftllexengine.integrity.IntegrityCheckFailedErrorwhennot accepted.
Protocol defining the contract every legislative pack must satisfy.
class ILegislativePack(Protocol):
@property
def metadata(self) -> LegislativePackMetadata: ...
@property
def function_registry(self) -> FunctionRegistry: ...
def validate_transaction(
self,
book: Book,
transaction: JournalTransaction,
) -> LegislativeValidationResult: ...
def localization_boot_config(self) -> LocalizationBootConfig: ...
def configure_localization(self, l10n: FluentLocalization) -> None: ...metadatamust be immutable.function_registrymust be a pack-local unfrozen copy of the shared FTLLexEngine registry.validate_transaction: business-rule validation; returns result, never raises on rule failures.localization_boot_config: returns aLocalizationBootConfigwith pack-localrequired_messagesandmessage_schemasdeclared; callers execute.boot()to obtain(FluentLocalization, LoadSummary, ...).configure_localization: called by the gateway immediately afterlocalization_boot_config().boot()to register pack-specific custom Fluent functions viaFluentLocalization.add_function(); packs without custom functions may implement as a no-op.
Mutable registry mapping pack codes to ILegislativePack implementations.
class LegislativePackRegistry:
def register(self, pack: ILegislativePack) -> None: ...
def resolve(self, pack_code: LegislativePackCode) -> ILegislativePack: ...
def available_pack_codes(self) -> tuple[LegislativePackCode, ...]: ...register: raisesValueErroron duplicate pack codes.resolve: raisesKeyErrorwhen the pack code is not registered.available_pack_codes: deterministic sorted tuple.- Implements
__contains__,__iter__, and__len__.
Function that returns a registry pre-loaded with the Latvia 2026 stub pack.
def create_default_pack_registry() -> LegislativePackRegistry:- Return:
LegislativePackRegistrycontainingLatviaStandard2026Pack. - Creates a fresh registry on each call; instances are independent.
Immutable legislative pack stub for Latvia, tax year 2026.
@dataclass(frozen=True, slots=True)
class LatviaStandard2026Pack:
metadata: LegislativePackMetadata # default_factory
function_registry: FunctionRegistry # default_factorymetadata.pack_code == "lv.standard.2026",territory_code == "LV",tax_year == 2026,currencies == ("EUR",).- Validation rule: any ledger entry with a non-
Nonetax_ratenot equal toDecimal("0.21")is flagged. - Validation rule:
book.legislative_pack != "lv.standard.2026"is flagged. localization_boot_config()returns aLocalizationBootConfigwith declaredrequired_messagesandmessage_schemas; loads FTL assets fromlocales/lv_lv/andlocales/en_us/applyingMANDATED_CACHE_CONFIG.configure_localization(l10n)registersROUND_EURand all other pack functions into the bootedFluentLocalizationvial10n.add_function().- Custom FTL function
ROUND_EURquantizes financial amounts to 2 decimal places usingROUND_HALF_UP. FTL usage:{ ROUND_EUR($amount) }. - FTL messages:
latvia-pack-name,vat-standard-rate,vat-amount.
Stateful runner that dispatches pack validation through a bounded InterpreterPool of reusable PEP 734 subinterpreters.
@dataclass(slots=True)
class LegislativeInterpreterRunner:
pool_min_size: int = 2
pool_max_size: int = 8
_pool: InterpreterPool # init=False; constructed from pool_min_size/pool_max_size
def validate(
self,
pack_code: str,
book: Book,
transaction: JournalTransaction,
) -> LegislativeValidationResult: ...
def close(self) -> None: ...| Name | Type | Req | Semantics |
|---|---|---|---|
pack_code |
str |
Y | Pack to resolve from the default registry |
book |
Book |
Y | Book context |
transaction |
JournalTransaction |
Y | Transaction to validate |
- Holds a bounded
InterpreterPool(default:min_size=2,max_size=8); interpreters are reused across calls, amortizing PEP 734 interpreter startup cost. validate()acquires one interpreter via context manager, executes_validate_in_subinterpreter, and releases it back to the pool.- Pack crashes are isolated; they cannot corrupt the core runtime.
- Return type is reconstructed from primitive round-trip data (no live objects cross interpreter boundary).
close()must be called on shutdown to release all pool interpreters;FinestVXService.close()handles this automatically.
Convenience function for one-shot subinterpreter legislative validation.
def validate_transaction_isolated(
pack_code: str,
book: Book,
transaction: JournalTransaction,
) -> LegislativeValidationResult:| Name | Type | Req | Semantics |
|---|---|---|---|
pack_code |
str |
Y | Pack to resolve |
book |
Book |
Y | Book context |
transaction |
JournalTransaction |
Y | Transaction to validate |
- Creates
LegislativeInterpreterRunner(pool_min_size=1, pool_max_size=1)for a single call, then closes it. - Raises:
KeyErrorwhenpack_codeis not in the default registry.