Check parser for ini name instead of manually listing known types

This commit is contained in:
Patrick Lannigan 2023-11-18 07:22:23 -05:00
parent e66388960d
commit d943866e8b
No known key found for this signature in database
GPG Key ID: BBF5D9DED1E4AAF9
1 changed files with 5 additions and 6 deletions

View File

@ -1653,7 +1653,6 @@ class Config:
#: Verbosity type for failed assertions (see :confval:`verbosity_assertions`). #: Verbosity type for failed assertions (see :confval:`verbosity_assertions`).
VERBOSITY_ASSERTIONS: Final = "assertions" VERBOSITY_ASSERTIONS: Final = "assertions"
_KNOWN_VERBOSITY_TYPES: Final = {VERBOSITY_ASSERTIONS}
_VERBOSITY_INI_DEFAULT: Final = "auto" _VERBOSITY_INI_DEFAULT: Final = "auto"
def get_verbosity(self, verbosity_type: Optional[str] = None) -> int: def get_verbosity(self, verbosity_type: Optional[str] = None) -> int:
@ -1689,14 +1688,14 @@ class Config:
""" """
global_level = self.option.verbose global_level = self.option.verbose
assert isinstance(global_level, int) assert isinstance(global_level, int)
if ( if verbosity_type is None:
verbosity_type is None
or verbosity_type not in Config._KNOWN_VERBOSITY_TYPES
):
return global_level return global_level
level = self.getini(Config._verbosity_ini_name(verbosity_type)) ini_name = Config._verbosity_ini_name(verbosity_type)
if ini_name not in self._parser._inidict:
return global_level
level = self.getini(ini_name)
if level == Config._VERBOSITY_INI_DEFAULT: if level == Config._VERBOSITY_INI_DEFAULT:
return global_level return global_level