mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-12-18 08:15:18 -05:00
* add basic pre-commit file * add flake8 * add isort * add pep585-upgrade (typing upgrades) * use namespace for import * add mypy * update ci for backend * flake8 scope * fix version format * update makefile * disable strict option (temporary) * fix mypy issues * upgrade type hints (pre-commit) * add vscode typing check * add types to dev deps * remote container draft * update setup script * update compose version * run setup on create * dev containers update * remove unused pages * update setup tips * expose ports * Update pre-commit to include flask8-print (#1053) * Add in flake8-print to pre-commit * pin version of flake8-print * formatting * update getting strated docs * add mypy to pre-commit * purge .mypy_cache on clean * drop mypy Co-authored-by: zackbcom <zackbcom@users.noreply.github.com>
25 lines
647 B
Python
25 lines
647 B
Python
from typing import TypeVar
|
|
|
|
from pydantic import BaseModel
|
|
|
|
T = TypeVar("T", bound=BaseModel)
|
|
U = TypeVar("U", bound=BaseModel)
|
|
|
|
|
|
def mapper(source: U, dest: T, **_) -> T:
|
|
"""
|
|
Map a source model to a destination model. Only top-level fields are mapped.
|
|
"""
|
|
|
|
for field in source.__fields__:
|
|
if field in dest.__fields__:
|
|
setattr(dest, field, getattr(source, field))
|
|
|
|
return dest
|
|
|
|
|
|
def cast(source: U, dest: type[T], **kwargs) -> T:
|
|
create_data = {field: getattr(source, field) for field in source.__fields__ if field in dest.__fields__}
|
|
create_data.update(kwargs or {})
|
|
return dest(**create_data)
|