JOJ3-config-generator/joj3_config_generator/models/common.py
张泊明518370910136 3f0fdd816b
All checks were successful
build / build (push) Successful in 2m16s
build / trigger-build-image (push) Successful in 9s
feat: strict mode toml loader
2025-09-17 01:13:51 -07:00

25 lines
730 B
Python

from typing import Union
import humanfriendly
from pydantic import BaseModel, ConfigDict
class Memory(int):
def __new__(cls, value: Union[str, int]) -> "Memory":
if isinstance(value, str):
parsed = humanfriendly.parse_size(value, binary=True)
return super().__new__(cls, parsed)
return super().__new__(cls, value)
class Time(int):
def __new__(cls, value: Union[str, int]) -> "Time":
if isinstance(value, str):
parsed = humanfriendly.parse_timespan(value) * 1_000_000_000 # ns
return super().__new__(cls, round(parsed))
return super().__new__(cls, value)
class StrictBaseModel(BaseModel):
model_config = ConfigDict(extra="forbid")