11import json
22import os
3- import typing as T
3+ from typing import Literal
44
55import toml
66import tomlkit
@@ -25,7 +25,7 @@ def file_ext(filepath: str):
2525
2626
2727def get_comment (
28- field : FieldInfo , format : T . Literal ["json" , "yaml" , "toml" ], add_choices : bool = True
28+ field : FieldInfo , format : Literal ["json" , "yaml" , "toml" ], add_choices : bool = True
2929) -> str | None :
3030 """
3131 Generate a comment string for a Pydantic field, including description and choices if they exist.
@@ -182,7 +182,7 @@ def load_json(cls, filepath: str):
182182 with open (filepath , "r" ) as f :
183183 return cls .model_validate (json .load (f ))
184184
185- def save_toml (self , filepath : str , overwrite : bool = True , comments : bool = True ):
185+ def save_toml (self , filepath : str , overwrite : bool = True , comments : bool = True ) -> None :
186186 if os .path .exists (filepath ) and not overwrite :
187187 raise FileExistsError (filepath )
188188 data = self .model_dump ()
@@ -219,14 +219,14 @@ def save_toml(self, filepath: str, overwrite: bool = True, comments: bool = True
219219 with open (filepath , "w" ) as f :
220220 tomlkit .dump (toml_doc , f )
221221
222- def save_json (self , filepath : str , overwrite : bool = True ):
222+ def save_json (self , filepath : str , overwrite : bool = True ) -> None :
223223 if os .path .exists (filepath ) and not overwrite :
224224 raise FileExistsError (filepath )
225225 data = self .model_dump ()
226226 with open (filepath , "w" ) as f :
227227 json .dump (data , f )
228228
229- def save_yaml (self , filepath : str , overwrite : bool = True , comments : bool = True ):
229+ def save_yaml (self , filepath : str , overwrite : bool = True , comments : bool = True ) -> None :
230230 if os .path .exists (filepath ) and not overwrite :
231231 raise FileExistsError (filepath )
232232
0 commit comments