From 96fddd481a77ea8908587915fdf34532f6b28545 Mon Sep 17 00:00:00 2001 From: Simon Jones Date: Thu, 21 Sep 2023 20:57:30 -0400 Subject: [PATCH] feat: pydantic BaseModel allows nullable integers greater than zero this also uses the pydantic conint type to constrain the min and max values to be greater than or equal to zero, as there is no need to have a check count be negative. --- chasten/results.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/chasten/results.py b/chasten/results.py index fd6eecad..6a005e75 100644 --- a/chasten/results.py +++ b/chasten/results.py @@ -3,10 +3,11 @@ import uuid from datetime import datetime from pathlib import Path -from typing import List, Union +from typing import List, Union, Optional from pyastgrep import search as pyastgrepsearch # type: ignore from pydantic import BaseModel +from pydantic.types import conint from chasten import debug @@ -67,8 +68,8 @@ class Check(BaseModel): id: str name: str description: str = "" - min: Union[None, int] = 0 - max: Union[None, int] = 0 + min: Optional[conint(ge=0)] = 0 + max: Optional[conint(ge=0)] = 0 pattern: str passed: bool matches: list[Match] = []