PY-PYDA0008 · implicit_arbitrary_type_model
Find Pydantic models that permit arbitrary field types globally.
This is a deterministic rule for python. Read its implementation.
Definition
Section titled “Definition”Report every model that directly derives from FrozenFlexModel. Prefer FrozenModel, then
mark the exact live-object boundary with Pydantic InstanceOf when a field holds a module,
protocol implementation, callable service, or other arbitrary runtime type. This preserves
validation for every ordinary field and makes the exceptional dependency visible where it is
declared.
Evidence
Section titled “Evidence”Each finding identifies the model and the exact flexible base expression. The value is the number of models whose whole schema accepts arbitrary types.
Exceptions
Section titled “Exceptions”Keep a flexible base only when arbitrary values are the model’s intended public data contract, rather than one or two injected runtime services. Projects that deliberately expose such a contract can disable this rule for that model’s module.
Examples
Section titled “Examples”Bad
`class Catalog(FrozenFlexModel): modules: list[ModuleType]` disables schema generation for thewhole model.
Goodclass Catalog(FrozenModel): modules: list[InstanceOf[ModuleType]] names and validates the
exceptional boundary directly.
References
Section titled “References”- Cites “Pydantic documentation”, arbitrary types. Open reference
- Cites “Pydantic documentation”, InstanceOf. Open reference