Efficient registration of models to converters by delaying import until serialization
#71 创建于 2025年9月7日
仓库指标
- 星标
- (2 个星标)
- PR 合并指标
- (30 天内没有已合并 PR)
描述
Currently, all asdf-pydantic models must be loaded into the same module where the Converter and Extension is defined since registration of the model to the converter is done dynamically via:
from asdf_pydantic import AsdfPydanticConverter
from mypackage import MyModel
converter = AsdfPydanticConverter()
converter.add_models(MyModel)
ASDF recommends delaying expensive imports in the construction of converters https://www.asdf-format.org/projects/asdf/en/latest/asdf/extending/converters.html#entry-point-performance-considerations
Overall, users should take care to avoid expensive imports during model definition, in general, regardless of ASDF. However since it is common to see behavioral methods in models relying on 3rd party (e.g., factories, adapters, CRUD), this can't always be avoided.
We may be able to provide a way for users to register the model's qualified names (i.e., package.module.object) to the converter. The challenge here is how to get the model-embedded tag and schema URIs without triggering imports. The URIs may be dynamic (e.g., requires importing the package __version__)