Repository Public MIT Research preview
1"""Un fait extrait porte toujours sa provenance : le fichier et le repère d'où il vient."""2from __future__ import annotations34from dataclasses import dataclass, replace56# Statuts possibles d'un fait, du moins fiable au plus fiable.7STATUTS = ("extrait", "déclaré", "estimé", "à confirmer", "en attente", "écarté", "vérifié")8910@dataclass(frozen=True)11class Fait:12 """Une valeur, son unité, sa source (fichier) et son repère (ligne, champ ou région)."""13 nom: str14 valeur: object15 unite: str16 source: str17 repere: str18 statut: str = "extrait"19 detail: str = ""2021 @property22 def provenance(self) -> str:23 return f"{self.source}:{self.repere}"2425 def avec(self, **changements) -> "Fait":26 return replace(self, **changements)272829def fr(nombre: int | float) -> str:30 """Nombre écrit à la française : 1237 -> « 1 237 »."""31 if isinstance(nombre, float) and nombre.is_integer():32 nombre = int(nombre)33 return f"{nombre:,}".replace(",", " ")34