Choose strict validation deliberately
Automatic conversion is useful at a text boundary, but it can hide a mistake inside an already typed system. Strict fields require the expected Python type instead of accepting every convertible value. In particular, a boolean should not silently become a measurement just because Python treats bool as a subclass of int.
Pydantic offers strictness per model, per field and per validation call. Choose the boundary that owns the policy. A strict model makes the rule visible to every caller.
from pydantic import BaseModel, ConfigDict
from pydantic import ValidationError
class Sample(BaseModel):
model_config = ConfigDict(strict=True)
count: int
try:
Sample(count="3")
except ValidationError as error:
print(error.errors()[0]["type"])Your task
Define strict Measurement with count: int. Implement strict_count(raw) returning its count. Reject numeric strings, bools and floats; accept zero and negative integers.
The explanation opens here once every check passes.