From 1d25bcda5ba24b5cd29473ea6a6c4cd0379bcf41 Mon Sep 17 00:00:00 2001 From: Alex Hayward Date: Thu, 14 Nov 2024 14:02:07 -0800 Subject: [PATCH] fix(schema): stronger typing for belongingness_ratio --- src/recordlinker/schemas/algorithm.py | 3 ++- src/recordlinker/schemas/link.py | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/recordlinker/schemas/algorithm.py b/src/recordlinker/schemas/algorithm.py index 5ae1adeb..5cb79a20 100644 --- a/src/recordlinker/schemas/algorithm.py +++ b/src/recordlinker/schemas/algorithm.py @@ -9,6 +9,7 @@ import typing import pydantic +from typing_extensions import Annotated from recordlinker.linking import matchers from recordlinker.models.mpi import BlockingKey @@ -78,7 +79,7 @@ class Algorithm(pydantic.BaseModel): description: typing.Optional[str] = None is_default: bool = False include_multiple_matches: bool = True - belongingness_ratio: tuple[float, float] + belongingness_ratio: tuple[Annotated[float, pydantic.Field(ge=0, le=1)], Annotated[float, pydantic.Field(ge=0, le=1)]] passes: typing.Sequence[AlgorithmPass] @pydantic.field_validator("belongingness_ratio", mode="before") diff --git a/src/recordlinker/schemas/link.py b/src/recordlinker/schemas/link.py index 1adcee7c..d0cbabc6 100644 --- a/src/recordlinker/schemas/link.py +++ b/src/recordlinker/schemas/link.py @@ -76,7 +76,9 @@ class LinkResponse(pydantic.BaseModel): "all Persons with which the Patient record possibly matches." ) - @pydantic.computed_field + # mypy doesn't support decorators on properties; https://github.com/python/mypy/issues/1362 + @pydantic.computed_field # type: ignore[misc] + @property def prediction(self) -> typing.Literal["match", "possible_match", "no_match"]: """ Record Linkage algorithm prediction.