@@ -77,7 +77,7 @@ class StateDict(TypedDict, total=False):
7777T = TypeVar ("T" , bound = "StateDict" )
7878
7979
80- def _get_defaults (cls : type [T ]) -> dict [ str , Any ] :
80+ def _get_defaults (cls : type [T ]) -> T :
8181 """Generate a default dict based on typed dict
8282
8383 This function recursively creates a nested dictionary structure that mirrors
@@ -127,21 +127,21 @@ async def get_state(state_yaml: str) -> StateDict:
127127 if not isfile (
128128 state_yaml
129129 ): # noqa: PTH113 - isfile is fine and simpler in this case.
130- return _get_defaults (StateDict ) # type: ignore
130+ return _get_defaults (StateDict )
131131
132132 try :
133133 async with aiofiles .open (state_yaml , mode = "r" ) as yaml_file :
134134 LOG .debug ("Loading state from yaml" )
135135 content = await yaml_file .read ()
136- state_yaml_payload : StateDict = yaml .safe_load (content )
136+ state_yaml_payload : StateDict | None = yaml .safe_load (content )
137137
138138 # Handle corrupted/empty YAML files
139139 if state_yaml_payload is None :
140140 LOG .warning (
141141 "State file %s is corrupted or empty, reinitializing with defaults" ,
142142 state_yaml ,
143143 )
144- defaults = _get_defaults (StateDict ) # type: ignore
144+ defaults = _get_defaults (StateDict )
145145 async with aiofiles .open (state_yaml , mode = "w" ) as yaml_file_write :
146146 content = yaml .dump (defaults )
147147 await yaml_file_write .write (content )
@@ -154,7 +154,7 @@ async def get_state(state_yaml: str) -> StateDict:
154154 state_yaml ,
155155 e ,
156156 )
157- defaults = _get_defaults (StateDict ) # type: ignore
157+ defaults = _get_defaults (StateDict )
158158 async with aiofiles .open (state_yaml , mode = "w" ) as yaml_file_write :
159159 content = yaml .dump (defaults )
160160 await yaml_file_write .write (content )
0 commit comments