11import json
22from dataclasses import dataclass
33from pathlib import Path
4- from typing import Any
4+ from typing import cast
55
66
77@dataclass (frozen = True )
88class ApplicationConfig :
9- launch : dict [str , Any ]
10- springsettings : dict [str , Any ]
9+ launch : dict [str , object ]
10+ springsettings : dict [str , object ]
1111
1212
1313def read_application_config (path : Path ) -> ApplicationConfig :
@@ -16,12 +16,12 @@ def read_application_config(path: Path) -> ApplicationConfig:
1616 if not isinstance (data , dict ):
1717 raise RuntimeError (f"Distribution configuration must be an object: { path } " )
1818 return ApplicationConfig (
19- launch = require_object (data , "launch" ),
20- springsettings = require_object (data , "springsettings" ),
19+ launch = require_object (cast ( "dict[str, object]" , data ) , "launch" ),
20+ springsettings = require_object (cast ( "dict[str, object]" , data ) , "springsettings" ),
2121 )
2222
2323
24- def render_start_script (game_name : str , launch : dict [str , Any ]) -> str :
24+ def render_start_script (game_name : str , launch : dict [str , object ]) -> str :
2525 map_name = require_string (launch , "map" )
2626 game_options = render_game_options (launch .get ("game_options" ))
2727 map_options = render_options_block ("MapOptions" , launch .get ("map_options" ))
@@ -51,22 +51,22 @@ def render_start_script(game_name: str, launch: dict[str, Any]) -> str:
5151 )
5252
5353
54- def write_springsettings (settings : dict [str , Any ], destination : Path ) -> Path :
54+ def write_springsettings (settings : dict [str , object ], destination : Path ) -> Path :
5555 values = {** settings , "DefaultStartScript" : "script.txt" }
5656 output = destination / "springsettings.cfg"
5757 lines = [f"{ key } ={ format_setting (value )} " for key , value in sorted (values .items ())]
5858 output .write_text ("\n " .join (lines ) + "\n " , encoding = "utf-8" )
5959 return output
6060
6161
62- def require_object (values : dict [str , Any ], key : str ) -> dict [str , Any ]:
62+ def require_object (values : dict [str , object ], key : str ) -> dict [str , object ]:
6363 value = values .get (key )
6464 if not isinstance (value , dict ):
6565 raise RuntimeError (f"Distribution configuration requires an object '{ key } '" )
66- return value
66+ return cast ( "dict[str, object]" , value )
6767
6868
69- def require_string (values : dict [str , Any ], key : str ) -> str :
69+ def require_string (values : dict [str , object ], key : str ) -> str :
7070 value = values .get (key )
7171 if not isinstance (value , str ) or not value :
7272 raise RuntimeError (f"Launch configuration requires a non-empty '{ key } ' value" )
@@ -86,12 +86,12 @@ def render_options_block(name: str, value: object) -> str:
8686 return f"\t [{ name } ]\n \t {{\n { entries } \n \t }}"
8787
8888
89- def require_options (value : object , name : str ) -> dict [str , Any ]:
89+ def require_options (value : object , name : str ) -> dict [str , object ]:
9090 if value is None :
9191 return {}
9292 if not isinstance (value , dict ):
9393 raise RuntimeError (f"Launch configuration '{ name } ' must be an object" )
94- return value
94+ return cast ( "dict[str, object]" , value )
9595
9696
9797def render_value (value : object ) -> str :
0 commit comments