-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_base.py
More file actions
22 lines (15 loc) · 908 Bytes
/
_base.py
File metadata and controls
22 lines (15 loc) · 908 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
"""Base class for every Pydantic contract that crosses a module or process seam.
Inheriting from ``StrictModel`` gives a contract ``extra="forbid"``: unknown
keys raise ``ValidationError`` at construction. Typos and renamed fields fail
immediately at the seam instead of silently surfacing three calls deep.
Classes that additionally want strict type checking (no implicit coercion —
e.g. rejecting ``"3.14"`` for a ``float`` field) opt in per-class via the
``strict=True`` keyword, e.g. ``class Foo(StrictModel, strict=True)``. This is
deliberate: models that cross the HTTP boundary need JSON coercion for UUIDs
and integers, while internal result contracts do not.
"""
from __future__ import annotations
from pydantic import BaseModel, ConfigDict
class StrictModel(BaseModel):
"""Base for every contract that crosses a module or process seam."""
model_config = ConfigDict(extra="forbid")