@@ -93,11 +93,16 @@ class OPTION(str, Enum):
9393}
9494
9595
96- def load_config_from_file (filename : str , section : str , options_ : options .Options = None , stop_on_error = True ) -> bool :
96+ def load_config_from_file (
97+ filename : str , section : ConfigSections , options_ : options .Options | None = None , * , stop_on_error : bool = True
98+ ) -> bool :
9799 """Opens file and read options from the given section. If stop_on_error is set,
98- the program stop if any error is found. Otherwise the result of the operation will be
100+ the program stop if any error is found. Otherwise, the result of the operation will be
99101 returned (True on success, False on failure)
100102 """
103+ assert isinstance (section , ConfigSections )
104+ section_ = section .value
105+
101106 if options_ is None :
102107 options_ = OPTIONS
103108
@@ -115,25 +120,30 @@ def load_config_from_file(filename: str, section: str, options_: options.Options
115120 sys .exit (1 )
116121 return False
117122
118- if section not in cfg .sections ():
119- errmsg .msg_output (f"Section '{ section } ' not found in config file '{ filename } '" )
123+ if section_ not in cfg .sections ():
124+ errmsg .msg_output (f"Section '{ section_ } ' not found in config file '{ filename } '" )
120125 if stop_on_error :
121126 sys .exit (1 )
122127 return False
123128
124129 parsing : Dict [type , Callable ] = {int : cfg .getint , float : cfg .getfloat , bool : cfg .getboolean }
125130
126- for opt in cfg .options (section ):
131+ for opt in cfg .options (section_ ):
127132 options_ [opt ].value = parsing .get (options_ [opt ].type , cfg .get )(section = section , option = opt )
128133
129134 return True
130135
131136
132- def save_config_into_file (filename : str , section : str , options_ : options .Options = None , stop_on_error = True ) -> bool :
137+ def save_config_into_file (
138+ filename : str , section : ConfigSections , options_ : options .Options | None = None , * , stop_on_error : bool = True
139+ ) -> bool :
133140 """Save config into config ini file into the given section. If stop_on_error is set,
134- the program stop. Otherwise the result of the operation will be
141+ the program stop. Otherwise, the result of the operation will be
135142 returned (True on success, False on failure)
136143 """
144+ assert isinstance (section , ConfigSections )
145+ section_ = section .value
146+
137147 if options_ is None :
138148 options_ = OPTIONS
139149
@@ -147,16 +157,16 @@ def save_config_into_file(filename: str, section: str, options_: options.Options
147157 sys .exit (1 )
148158 return False
149159
150- cfg [section ] = {}
160+ cfg [section_ ] = {}
151161 for opt_name , opt in options_ ().items ():
152162 if opt_name .startswith ("__" ) or opt .value is None or opt_name in OPTIONS_NOT_SAVED :
153163 continue
154164
155165 if opt .type == bool :
156- cfg [section ][opt_name ] = str (opt .value ).lower ()
166+ cfg [section_ ][opt_name ] = str (opt .value ).lower ()
157167 continue
158168
159- cfg [section ][opt_name ] = str (opt .value )
169+ cfg [section_ ][opt_name ] = str (opt .value )
160170
161171 try :
162172 with open (filename , "wt" , encoding = "utf-8" ) as f :
@@ -170,7 +180,7 @@ def save_config_into_file(filename: str, section: str, options_: options.Options
170180 return True
171181
172182
173- def init ():
183+ def init () -> None :
174184 """Default Options and Compilation Flags"""
175185 OPTIONS (Action .CLEAR )
176186
0 commit comments