refine code

This commit is contained in:
geekan 2024-01-12 15:56:07 +08:00
parent 1edff983f0
commit 31eb3fe0ee
5 changed files with 20 additions and 17 deletions

View file

@ -23,10 +23,10 @@ class YamlModel(BaseModel):
return yaml.safe_load(file)
@classmethod
def model_validate_yaml(cls, file_path: Path) -> "YamlModel":
def from_yaml_file(cls, file_path: Path) -> "YamlModel":
return cls(**cls.read_yaml(file_path))
def model_dump_yaml(self, file_path: Path) -> None:
def to_yaml_file(self, file_path: Path) -> None:
with open(file_path, "w") as file:
yaml.dump(self.model_dump(), file)