22import json
33from datetime import datetime
44from pathlib import Path
5+ from typing import Any
56
67from graver .exceptions import (
78 PromptNotFoundError ,
@@ -57,7 +58,7 @@ def save(self, name: str, content: str) -> str:
5758
5859 history_path = self ._history_file (name )
5960 try :
60- history : list [dict ] = (
61+ history : list [dict [ str , Any ] ] = (
6162 json .loads (history_path .read_text (encoding = "utf-8" ))
6263 if history_path .exists ()
6364 else []
@@ -94,7 +95,7 @@ def get(self, name: str, version: str | None = None) -> str:
9495
9596 return target .read_text (encoding = "utf-8" )
9697
97- def history (self , name : str ) -> list [dict ]:
98+ def history (self , name : str ) -> list [dict [ str , Any ] ]:
9899 prompt_dir = self ._prompt_dir (name )
99100 if not prompt_dir .exists ():
100101 raise PromptNotFoundError (
@@ -105,9 +106,12 @@ def history(self, name: str) -> list[dict]:
105106 if not history_path .exists ():
106107 return []
107108
108- return json .loads (history_path .read_text (encoding = "utf-8" ))
109+ result : list [dict [str , Any ]] = json .loads (
110+ history_path .read_text (encoding = "utf-8" )
111+ )
112+ return result
109113
110- def diff (self , name : str , v1 : str , v2 : str ) -> dict :
114+ def diff (self , name : str , v1 : str , v2 : str ) -> dict [ str , list [ str ]] :
111115 lines1 = self .get (name , v1 ).splitlines (keepends = True )
112116 lines2 = self .get (name , v2 ).splitlines (keepends = True )
113117
@@ -151,7 +155,9 @@ def delete_version(self, name: str, version: str) -> None:
151155 history_path = self ._history_file (name )
152156 if history_path .exists ():
153157 try :
154- history = json .loads (history_path .read_text (encoding = "utf-8" ))
158+ history : list [dict [str , Any ]] = json .loads (
159+ history_path .read_text (encoding = "utf-8" )
160+ )
155161 history = [e for e in history if e ["version" ] != version ]
156162 history_path .write_text (
157163 json .dumps (history , indent = 2 , ensure_ascii = False ), encoding = "utf-8"
@@ -182,5 +188,6 @@ def get_main(self, name: str) -> str | None:
182188 main_path = self ._main_file (name )
183189 if not main_path .exists ():
184190 return None
185- data = json .loads (main_path .read_text (encoding = "utf-8" ))
186- return data .get ("version" )
191+ data : dict [str , Any ] = json .loads (main_path .read_text (encoding = "utf-8" ))
192+ version : str | None = data .get ("version" )
193+ return version
0 commit comments