11"""Central registry for all object mappers."""
22
3+ from types import MappingProxyType
34from typing import TypeVar
45
56from ga4gh .va_spec .base import CohortAlleleFrequencyStudyResult
1314class MapperRegistry :
1415 """Central registry for all object mappers."""
1516
16- def __init__ (self ) -> None :
17- """Initialize the MapperRegistry with known mappers."""
18- self .anyvlm_to_db_mapping = {
19- CohortAlleleFrequencyStudyResult : orm .AlleleFrequencyData
20- }
17+ va_model_to_db_mapping : MappingProxyType = MappingProxyType (
18+ {CohortAlleleFrequencyStudyResult : orm .AlleleFrequencyData }
19+ )
2120
22- self . _mappers : dict [type , BaseMapper ] = {
23- orm .AlleleFrequencyData : AlleleFrequencyMapper ()
24- }
21+ _mappers : MappingProxyType [type , BaseMapper ] = MappingProxyType (
22+ { orm .AlleleFrequencyData : AlleleFrequencyMapper ()}
23+ )
2524
2625 def get_mapper (self , entity_type : type [T ]) -> BaseMapper :
2726 """Get mapper for the given entity type."""
@@ -37,7 +36,7 @@ def from_db_entity(self, db_entity): # noqa: ANN201, ANN001
3736
3837 def to_db_entity (self , anyvlm_entity ) -> orm .Base : # noqa: ANN001
3938 """Convert any VA-Spec model to its corresponding DB entity."""
40- db_type = self .anyvlm_to_db_mapping .get (type (anyvlm_entity ))
39+ db_type = self .va_model_to_db_mapping .get (type (anyvlm_entity ))
4140 if db_type is None :
4241 raise ValueError (
4342 f"No DB entity type mapped for VRS model: { type (anyvlm_entity )} "
0 commit comments