@@ -82,10 +82,7 @@ def default_username(self) -> str:
8282 :returns: The `default-user` username or an empty string.
8383 :rtype: str
8484 """
85- if self .config .has_option ("DEFAULT" , "default-user" ):
86- return self .config .get ("DEFAULT" , "default-user" )
87-
88- return ""
85+ return self .config .get ("DEFAULT" , "default-user" , fallback = "" )
8986
9087 def set_user (self , username : str ):
9188 """
@@ -153,15 +150,11 @@ def get_token(self) -> str:
153150 :rtype: str
154151 """
155152 if self .used_env_token :
156- return os .environ . get (ENV_TOKEN_NAME , None )
153+ return os .getenv (ENV_TOKEN_NAME , None )
157154
158- if self .config .has_option (
159- self .username or self .default_username (), "token"
160- ):
161- return self .config .get (
162- self .username or self .default_username (), "token"
163- )
164- return ""
155+ return self .config .get (
156+ self .username or self .default_username (), "token" , fallback = ""
157+ )
165158
166159 def get_value (self , key : str ) -> Optional [Any ]:
167160 """
@@ -180,12 +173,9 @@ def get_value(self, key: str) -> Optional[Any]:
180173 current user.
181174 :rtype: any
182175 """
183- username = self .username or self .default_username ()
184-
185- if not self .config .has_option (username , key ):
186- return None
187-
188- return self .config .get (username , key )
176+ return self .config .get (
177+ self .username or self .default_username (), key , fallback = None
178+ )
189179
190180 def get_bool (self , key : str ) -> bool :
191181 """
@@ -204,12 +194,10 @@ def get_bool(self, key: str) -> bool:
204194 current user.
205195 :rtype: any
206196 """
207- username = self .username or self .default_username ()
208-
209- if not self .config .has_option (username , key ):
210- return False
211197
212- return self .config .getboolean (username , key )
198+ return self .config .getboolean (
199+ self .username or self .default_username (), key , fallback = False
200+ )
213201
214202 # plugin methods - these are intended for plugins to utilize to store their
215203 # own persistent config information
@@ -255,13 +243,10 @@ def plugin_get_value(self, key: str) -> Optional[Any]:
255243 "No running plugin to retrieve configuration for!"
256244 )
257245
258- username = self .username or self .default_username ()
246+ username = self .username or self .default_username () or "DEFAULT"
259247 full_key = f"plugin-{ self .running_plugin } -{ key } "
260248
261- if not self .config .has_option (username , full_key ):
262- return None
263-
264- return self .config .get (username , full_key )
249+ return self .config .get (username , full_key , fallback = None )
265250
266251 # TODO: this is more of an argparsing function than it is a config function
267252 # might be better to move this to argparsing during refactor and just have
@@ -308,11 +293,8 @@ def update(
308293 # these don't get included in the updated namespace
309294 if key .startswith ("plugin-" ):
310295 continue
311- value = None
312- if self .config .has_option (username , key ):
313- value = self .config .get (username , key )
314- else :
315- value = ns_dict [key ]
296+
297+ value = self .config .get (username , key , fallback = ns_dict .get (key ))
316298
317299 if not value :
318300 continue
@@ -553,7 +535,7 @@ def _handle_no_default_user(self): # pylint: disable=too-many-branches
553535
554536 if len (users ) == 0 :
555537 # config is new or _really_ old
556- token = self .config .get ("DEFAULT" , "token" )
538+ token = self .config .get ("DEFAULT" , "token" , fallback = None )
557539
558540 if token is not None :
559541 # there's a token in the config - configure that user
0 commit comments