PY-MODE0003 · approved_model_foundation
Require direct Pydantic models to use an established approved house base.
This is a deterministic rule for python. Read its implementation.
Definition
Section titled “Definition”First establish project policy, either by finding a module anywhere in the repository that
imports a foundation from patos or from a common.bases module, or by finding a base the
project itself owns, one declaring no fields that other classes already derive. A module named
after a folder establishes nothing on its own, since a name says nothing about what a module
declares. Then inspect project-owned top-level classes and report direct subclasses of an
imported pydantic.BaseModel that do not also inherit an approved base. Resolve direct
imports, module imports, and aliases through the bindings each file states. Each bypassing
class contributes one to the result.
Evidence
Section titled “Evidence”Each finding identifies the direct model class and its source range. Which foundations count
as approved is the provider’s single project-specific input, and it recognizes the two house
homes for one. The value is the number of classes deriving pydantic.BaseModel without an
approved foundation.
Exceptions
Section titled “Exceptions”Abstain when the project has not established a house foundation. The foundation itself derives
Pydantic directly by design, so a base owning no fields that states the model_config its
subclasses inherit is never reported, whatever file or folder holds it. Ignore Pydantic
dataclasses, RootModel, dynamic create_model calls, unresolved bases, nested classes, and
subclasses of a project foundation because their Pydantic ancestry is not locally proven. The
repository’s Git ignore files decide whether generated and vendored sources are in the scan,
and per-rule globs can narrow it further.
Examples
Section titled “Examples”Bad
After `from patos import FrozenModel` establishes the policy, this direct foundation bypassesit.
.. code-block:: python
from pydantic import BaseModel
class User(BaseModel): name. str
GoodThe project-owned foundation makes mutability and validation policy explicit.
.. code-block:: python
from patos import FrozenModel
class User(FrozenModel): name. str
References
Section titled “References”- Cites “Pydantic documentation”, models. Open reference
- Cites “Pydantic documentation”, custom base model guidance. Open reference
- Cites “PEP 8, Style Guide for Python Code”, public and internal interfaces. Open reference