diff --git a/src/mednet/libs/common/scripts/utils.py b/src/mednet/libs/common/scripts/utils.py index c11cc8fbfc23dad1d7b76c0657d8bd2f69dd71ad..e9e8c087f1b34bf381095e5dd00e58cb519cfb61 100644 --- a/src/mednet/libs/common/scripts/utils.py +++ b/src/mednet/libs/common/scripts/utils.py @@ -8,6 +8,7 @@ import logging import pathlib import re import shutil +import typing import lightning.pytorch import lightning.pytorch.callbacks @@ -16,6 +17,17 @@ from mednet.libs.common.engine.device import SupportedPytorchDevice logger = logging.getLogger("mednet") +JSONable: typing.TypeAlias = ( + typing.Mapping[str, "JSONable"] + | typing.Sequence["JSONable"] + | str + | int + | float + | bool + | None +) +"""Defines types that can be encoded in a JSON string.""" + def model_summary( model: torch.nn.Module, @@ -198,7 +210,7 @@ def execution_metadata() -> dict[str, int | float | str | dict[str, str] | list[ } -def save_json_with_backup(path: pathlib.Path, data: dict | list) -> None: +def save_json_with_backup(path: pathlib.Path, data: JSONable) -> None: """Save a dictionary into a JSON file with path checking and backup. This function will save a dictionary into a JSON file. It will check to