Skip to content

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.

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.

Each finding identifies the model and the exact flexible base expression. The value is the number of models whose whole schema accepts arbitrary types.

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.

Bad

`class Catalog(FrozenFlexModel): modules: list[ModuleType]` disables schema generation for the
whole model.
Good

class Catalog(FrozenModel): modules: list[InstanceOf[ModuleType]] names and validates the exceptional boundary directly.