diff --git a/poetry.lock b/poetry.lock index bd3c808..a88f0eb 100644 --- a/poetry.lock +++ b/poetry.lock @@ -2482,41 +2482,6 @@ loguru = "*" [package.extras] test = ["pytest", "pytest-cov"] -[[package]] -name = "python-box" -version = "7.2.0" -description = "Advanced Python dictionaries with dot notation access" -optional = false -python-versions = ">=3.8" -files = [ - {file = "python_box-7.2.0-cp310-cp310-macosx_11_0_x86_64.whl", hash = "sha256:6bdeec791e25258351388b3029a3ec5da302bb9ed3be175493c43cdc6c47f5e3"}, - {file = "python_box-7.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:c449f7b3756a71479fa9c61a86e344ac00ed782a66d7662590f0afa294249d18"}, - {file = "python_box-7.2.0-cp310-cp310-win_amd64.whl", hash = "sha256:6b0d61f182d394106d963232854e495b51edc178faa5316a797be1178212d7e0"}, - {file = "python_box-7.2.0-cp311-cp311-macosx_10_9_universal2.whl", hash = "sha256:e2d752de8c1204255bf7b0c814c59ef48293c187a7e9fdcd2fefa28024b72032"}, - {file = "python_box-7.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:e8a6c35ea356a386077935958a5debcd5b229b9a1b3b26287a52dfe1a7e65d99"}, - {file = "python_box-7.2.0-cp311-cp311-win_amd64.whl", hash = "sha256:32ed58ec4d9e5475efe69f9c7d773dfea90a6a01979e776da93fd2b0a5d04429"}, - {file = "python_box-7.2.0-cp312-cp312-macosx_10_9_universal2.whl", hash = "sha256:2a2d664c6a27f7515469b6f1e461935a2038ee130b7d194b4b4db4e85d363618"}, - {file = "python_box-7.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:e8a5a7365db1aaf600d3e8a2747fcf6833beb5d45439a54318548f02e302e3ec"}, - {file = "python_box-7.2.0-cp312-cp312-win_amd64.whl", hash = "sha256:739f827056ea148cbea3122d4617c994e829b420b1331183d968b175304e3a4f"}, - {file = "python_box-7.2.0-cp38-cp38-macosx_11_0_x86_64.whl", hash = "sha256:2617ef3c3d199f55f63c908f540a4dc14ced9b18533a879e6171c94a6a436f23"}, - {file = "python_box-7.2.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ffd866bed03087b1d8340014da8c3aaae19135767580641df1b4ae6fff6ac0aa"}, - {file = "python_box-7.2.0-cp38-cp38-win_amd64.whl", hash = "sha256:9681f059e7e92bdf20782cd9ea6e533d4711fc7b8c57a462922a025d46add4d0"}, - {file = "python_box-7.2.0-cp39-cp39-macosx_11_0_x86_64.whl", hash = "sha256:6b59b1e2741c9ceecdf5a5bd9b90502c24650e609cd824d434fed3b6f302b7bb"}, - {file = "python_box-7.2.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:e23fae825d809ae7520fdeac88bb52be55a3b63992120a00e381783669edf589"}, - {file = "python_box-7.2.0-cp39-cp39-win_amd64.whl", hash = "sha256:573b1abdcb7bd745fa404444f060ee62fc35a74f067181e55dcb43cfe92f2827"}, - {file = "python_box-7.2.0-py3-none-any.whl", hash = "sha256:a3c90832dd772cb0197fdb5bc06123b6e1b846899a1b53d9c39450d27a584829"}, - {file = "python_box-7.2.0.tar.gz", hash = "sha256:551af20bdab3a60a2a21e3435120453c4ca32f7393787c3a5036e1d9fc6a0ede"}, -] - -[package.extras] -all = ["msgpack", "ruamel.yaml (>=0.17)", "toml"] -msgpack = ["msgpack"] -pyyaml = ["PyYAML"] -ruamel-yaml = ["ruamel.yaml (>=0.17)"] -toml = ["toml"] -tomli = ["tomli", "tomli-w"] -yaml = ["ruamel.yaml (>=0.17)"] - [[package]] name = "python-dateutil" version = "2.9.0.post0" @@ -3302,4 +3267,4 @@ type = ["pytest-mypy"] [metadata] lock-version = "2.0" python-versions = "^3.10" -content-hash = "18e222c6dad4e586ace3f58dd67479bb7829c2e36f3c3ebc736b4f127d4a4e16" +content-hash = "20fc83d1172d99d28cd8eeeb83bb6f79e622364de9d7de9687c544ae3b6e507a" diff --git a/pyproject.toml b/pyproject.toml index 4e5c46a..ce21eee 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -30,7 +30,6 @@ pendulum = "^3.0.0" pint = "0.24.*" pycognito = "2024.5.1" pydantic = "2.7.3" -python-box = "^7.2.0" [tool.poetry.group.dev.dependencies] aioresponses = "0.7.6" @@ -66,6 +65,7 @@ mkdocstrings-python = "1.10.3" pkginfo = "<1.11" setuptools = "^70.0.0" virtualenv = "^20.26.2" +griffe = "^1.3.1" [build-system] diff --git a/src/otf_api/models/base.py b/src/otf_api/models/base.py index 61bf0ef..72dfa8d 100644 --- a/src/otf_api/models/base.py +++ b/src/otf_api/models/base.py @@ -1,136 +1,9 @@ -import inspect -import typing -from typing import ClassVar, TypeVar +from typing import ClassVar -from box import Box from pydantic import BaseModel, ConfigDict -if typing.TYPE_CHECKING: - from pydantic.main import IncEx -T = TypeVar("T", bound="OtfItemBase") - - -class BetterDumperMixin: - """A better dumper for Pydantic models that includes properties in the dumped data. Must be mixed - into a Pydantic model, as it overrides the `model_dump` method. - - Includes support for nested models, and has an option to not include properties when dumping. - """ - - def get_properties(self) -> list[str]: - """Get the properties of the model.""" - cls = type(self) - - properties: list[str] = [] - methods = inspect.getmembers(self, lambda f: not (inspect.isroutine(f))) - for prop_name, _ in methods: - if hasattr(cls, prop_name) and isinstance(getattr(cls, prop_name), property): - properties.append(prop_name) - - return properties - - @typing.overload - def model_dump( - self, - *, - mode: typing.Literal["json", "python"] | str = "python", - include: "IncEx" = None, - exclude: "IncEx" = None, - by_alias: bool = False, - exclude_unset: bool = False, - exclude_defaults: bool = False, - exclude_none: bool = False, - round_trip: bool = False, - warnings: bool = True, - include_properties: bool = True, - ) -> Box[str, typing.Any]: ... - - @typing.overload - def model_dump( - self, - *, - mode: typing.Literal["json", "python"] | str = "python", - include: "IncEx" = None, - exclude: "IncEx" = None, - by_alias: bool = False, - exclude_unset: bool = False, - exclude_defaults: bool = False, - exclude_none: bool = False, - round_trip: bool = False, - warnings: bool = True, - include_properties: bool = False, - ) -> dict[str, typing.Any]: ... - - def model_dump( - self, - *, - mode: typing.Literal["json", "python"] | str = "python", - include: "IncEx" = None, - exclude: "IncEx" = None, - by_alias: bool = False, - exclude_unset: bool = False, - exclude_defaults: bool = False, - exclude_none: bool = False, - round_trip: bool = False, - warnings: bool = True, - include_properties: bool = True, - ) -> dict[str, typing.Any] | Box[str, typing.Any]: - """Usage docs: https://docs.pydantic.dev/2.4/concepts/serialization/#modelmodel_dump - - Generate a dictionary representation of the model, optionally specifying which fields to include or exclude. - - Args: - mode: The mode in which `to_python` should run. - If mode is 'json', the dictionary will only contain JSON serializable types. - If mode is 'python', the dictionary may contain any Python objects. - include: A list of fields to include in the output. - exclude: A list of fields to exclude from the output. - by_alias: Whether to use the field's alias in the dictionary key if defined. - exclude_unset: Whether to exclude fields that are unset or None from the output. - exclude_defaults: Whether to exclude fields that are set to their default value from the output. - exclude_none: Whether to exclude fields that have a value of `None` from the output. - round_trip: Whether to enable serialization and deserialization round-trip support. - warnings: Whether to log warnings when invalid fields are encountered. - include_properties: Whether to include properties in the dumped data. - - Returns: - A dictionary representation of the model. Will be a `Box` if `include_properties` is `True`, otherwise a - regular dictionary. - - """ - dumped_data = typing.cast(BaseModel, super()).model_dump( - mode=mode, - include=include, - exclude=exclude, - by_alias=by_alias, - exclude_unset=exclude_unset, - exclude_defaults=exclude_defaults, - exclude_none=exclude_none, - round_trip=round_trip, - warnings=warnings, - ) - - if not include_properties: - return dumped_data - - properties = self.get_properties() - - # set properties to their values - for prop_name in properties: - dumped_data[prop_name] = getattr(self, prop_name) - - # if the property is a Pydantic model, dump it as well - for k, v in dumped_data.items(): - if issubclass(type(getattr(self, k)), BaseModel): - dumped_data[k] = getattr(self, k).model_dump() - elif hasattr(v, "model_dump"): - dumped_data[k] = v.model_dump() - - return Box(dumped_data) - - -class OtfItemBase(BetterDumperMixin, BaseModel): +class OtfItemBase(BaseModel): model_config: ClassVar[ConfigDict] = ConfigDict(arbitrary_types_allowed=True, extra="allow")