tempor.core.pydantic_utils module¶
Module for pydantic-related utilities.
- tempor.core.pydantic_utils.is_pydantic_dataclass(cls: type) bool[source]¶
A helper function to check if a class is a
pydanticdataclass.
- tempor.core.pydantic_utils.make_pydantic_dataclass(builtin_dataclass: type) type[source]¶
Workaround for a
pydanticedge case issue when callingpydantic.dataclass(<builtin_dataclass>)more than once wherebuiltin_dataclasshas a default factory filed after a keyword parameter.E.g. the following would normally fail, this works around the issue.
from typing import List import dataclasses import pydantic @dataclasses.dataclass class MyDataclass: a: str = "string" b: List[int] = dataclasses.field(default_factory=lambda: [1, 2, 3]) pydantic.dataclasses.dataclass(MyDataclass) # OK. pydantic.dataclasses.dataclass(MyDataclass) # TypeError.
- tempor.core.pydantic_utils.validate_arguments(*args: Any, **kwargs: Any) Callable[[Callable[[P], T]], Callable[[P], T]][source]¶
Uses the
Callable[P, T]approach to type the pydanticvalidate_argumentsdecorator. Helpsmypyto correctly understand typing of functions that are decorated by this.See: - https://stackoverflow.com/a/74080156 - https://docs.python.org/3/library/typing.html#typing.ParamSpec