11import tomllib
22from pathlib import Path
3- from typing import Any
3+ from typing import Any , Literal
44
55import rlbot .flat as flat
66from rlbot .utils .logging import DEFAULT_LOGGER as logger
@@ -11,7 +11,7 @@ class ConfigParsingException(Exception):
1111 pass
1212
1313
14- def __enum (table : dict , key : str , enum : Any , default : int = 0 ) -> Any :
14+ def __enum (table : dict [ str , str | Any ] , key : str , enum : Any , default : int = 0 ) -> Any :
1515 if key not in table :
1616 return enum (default )
1717 try :
@@ -24,35 +24,35 @@ def __enum(table: dict, key: str, enum: Any, default: int = 0) -> Any:
2424 )
2525
2626
27- def __str (table : dict , key : str , default : str = "" ) -> str :
27+ def __str (table : dict [ str , str | Any ] , key : str , default : str = "" ) -> str :
2828 v = table .get (key , default )
2929 if isinstance (v , str ):
3030 return v
3131 raise ConfigParsingException (f"'{ key } ' has value { repr (v )} . Expected a string." )
3232
3333
34- def __bool (table : dict , key : str , default : bool = False ) -> bool :
34+ def __bool (table : dict [ str , bool | Any ] , key : str , default : bool = False ) -> bool :
3535 v = table .get (key , default )
3636 if isinstance (v , bool ):
3737 return v
3838 raise ConfigParsingException (f"'{ key } ' has value { repr (v )} . Expected a bool." )
3939
4040
41- def __int (table : dict , key : str , default : int = 0 ) -> int :
41+ def __int (table : dict [ str , int | Any ] , key : str , default : int = 0 ) -> int :
4242 v = table .get (key , default )
4343 if isinstance (v , int ):
4444 return v
4545 raise ConfigParsingException (f"'{ key } ' has value { repr (v )} . Expected an int." )
4646
4747
48- def __table (table : dict , key : str ) -> dict :
48+ def __table (table : dict [ str , dict [ str , Any ] | Any ], key : str ) -> dict [ str , Any ] :
4949 v = table .get (key , dict ())
5050 if isinstance (v , dict ):
51- return v
51+ return v # type: ignore
5252 raise ConfigParsingException (f"'{ key } ' has value { repr (v )} . Expected a table." )
5353
5454
55- def __team (table : dict ) -> int :
55+ def __team (table : dict [ str , Literal [ "blue" , "orange" , 0 , 1 ] | Any ] ) -> int :
5656 if "team" not in table :
5757 return 0
5858 v = table ["team" ]
@@ -81,7 +81,7 @@ def load_match_config(config_path: Path | str) -> flat.MatchConfiguration:
8181 match_table = __table (config , "match" )
8282 mutator_table = __table (config , "mutators" )
8383
84- players = []
84+ players : list [ flat . PlayerConfiguration ] = []
8585 for car_table in config .get ("cars" , []):
8686 car_config = __str (car_table , "config_file" )
8787 name = __str (car_table , "name" )
@@ -101,20 +101,24 @@ def load_match_config(config_path: Path | str) -> flat.MatchConfiguration:
101101 variety , use_config = flat .Human (), False
102102 case "partymember" :
103103 logger .warning ("PartyMember player type is not supported yet." )
104- variety , use_config = flat .PartyMember , False
104+ variety , use_config = flat .PartyMember () , False
105105 case t :
106106 raise ConfigParsingException (
107107 f"Invalid player type { repr (t )} for player { len (players )} ."
108108 )
109109
110110 if use_config and car_config :
111111 abs_config_path = (config_path .parent / car_config ).resolve ()
112- players .append (load_player_config (abs_config_path , variety , team , name , loadout_file )) # type: ignore
112+ players .append (
113+ load_player_config (abs_config_path , variety , team , name , loadout_file ) # type: ignore
114+ )
113115 else :
114116 loadout = load_player_loadout (loadout_file , team ) if loadout_file else None
115- players .append (flat .PlayerConfiguration (variety , name , team , loadout = loadout )) # type: ignore
117+ players .append (
118+ flat .PlayerConfiguration (variety , name , team , loadout = loadout )
119+ )
116120
117- scripts = []
121+ scripts : list [ flat . ScriptConfiguration ] = []
118122 for script_table in config .get ("scripts" , []):
119123 if script_config := __str (script_table , "config_file" ):
120124 abs_config_path = (config_path .parent / script_config ).resolve ()
0 commit comments