2323from Utils import parse_yamls , version_tuple , __version__ , tuplize_version
2424
2525
26- def mystery_argparse (argv : list [str ] | None = None ):
26+ def mystery_argparse (argv : list [str ] | None = None ) -> argparse . Namespace :
2727 from settings import get_settings
2828 settings = get_settings ()
2929 defaults = settings .generator
@@ -68,7 +68,7 @@ def mystery_argparse(argv: list[str] | None = None):
6868 args .weights_file_path = os .path .join (args .player_files_path , args .weights_file_path )
6969 if not os .path .isabs (args .meta_file_path ):
7070 args .meta_file_path = os .path .join (args .player_files_path , args .meta_file_path )
71- args .plando : PlandoOptions = PlandoOptions .from_option_string (args .plando )
71+ args .plando = PlandoOptions .from_option_string (args .plando )
7272
7373 return args
7474
@@ -135,7 +135,7 @@ def main(args=None) -> tuple[argparse.Namespace, int]:
135135 else :
136136 weights_for_file .append (yaml )
137137 weights_cache [fname ] = tuple (weights_for_file )
138-
138+
139139 except Exception as e :
140140 logging .exception (f"Exception reading weights in file { fname } " )
141141 player_errors .append (
@@ -205,7 +205,7 @@ def main(args=None) -> tuple[argparse.Namespace, int]:
205205 else :
206206 yaml [category_name ][key ] = option
207207
208- settings_cache : dict [str , tuple [argparse .Namespace , ...]] = {fname : None for fname in weights_cache }
208+ settings_cache : dict [str , tuple [argparse .Namespace , ...] | None ] = {fname : None for fname in weights_cache }
209209 if args .sameoptions :
210210 for fname , yamls in weights_cache .items ():
211211 try :
@@ -225,7 +225,7 @@ def main(args=None) -> tuple[argparse.Namespace, int]:
225225 player_path_cache : dict [int , str ] = {}
226226 for player in range (1 , args .multi + 1 ):
227227 player_path_cache [player ] = player_files .get (player , args .weights_file_path )
228- name_counter = Counter ()
228+ name_counter : Counter [ str ] = Counter ()
229229 args .player_options = {}
230230
231231 player = 1
@@ -241,13 +241,10 @@ def main(args=None) -> tuple[argparse.Namespace, int]:
241241 try :
242242 # Use the cached settings object if it exists, otherwise roll settings within the try-catch
243243 # Invariant: settings_cache[path] and weights_cache[path] have the same length
244- settingsObject : argparse .Namespace = (
245- settings_cache [path ][doc_index ]
246- if settings_cache [path ]
247- else roll_settings (yaml , args .plando )
248- )
249-
250- for k , v in vars (settingsObject ).items ():
244+ cached = settings_cache [path ]
245+ settings_object : argparse .Namespace = (cached [doc_index ] if cached else roll_settings (yaml , args .plando ))
246+
247+ for k , v in vars (settings_object ).items ():
251248 if v is not None :
252249 try :
253250 getattr (args , k )[player ] = v
@@ -365,7 +362,7 @@ def get_value(self, key, args, kwargs):
365362 return kwargs .get (key , "{" + key + "}" )
366363
367364
368- def handle_name (name : str , player : int , name_counter : Counter ):
365+ def handle_name (name : str , player : int , name_counter : Counter [ str ] ):
369366 name_counter [name .lower ()] += 1
370367 number = name_counter [name .lower ()]
371368 new_name = "%" .join ([x .replace ("%number%" , "{number}" ).replace ("%player%" , "{player}" ) for x in name .split ("%%" )])
@@ -503,7 +500,7 @@ def roll_triggers(weights: dict, triggers: list, valid_keys: set) -> dict:
503500 return weights
504501
505502
506- def handle_option (ret : argparse .Namespace , game_weights : dict , option_key : str , option : type ( Options .Option ) , plando_options : PlandoOptions ):
503+ def handle_option (ret : argparse .Namespace , game_weights : dict , option_key : str , option : type [ Options .Option ] , plando_options : PlandoOptions ):
507504 try :
508505 if option_key in game_weights :
509506 if not option .supports_weighting :
0 commit comments