typo in exception handling for get, NoSectionError will be caught as well; initialise ConfigParser in __init__, not in class

This commit is contained in:
Marcus Stoegbauer 2024-03-30 21:42:06 +01:00
parent 37954e432c
commit e6d2b9a7bc

View File

@ -4,13 +4,14 @@ import sys
class Conf(object):
_confobj = configparser.ConfigParser(dict(HOME=os.environ.get('HOME')))
_confobj = None
_cfgfiles = []
debug = None
def __init__(self, filename=None, debug=None, force_filename=False):
if debug:
self.set_debug(debug)
self._confobj = configparser.ConfigParser(dict(HOME=os.environ.get('HOME')))
filenames = []
if not force_filename:
# default config files are $HOME/etc/userconfig2.conf and
@ -44,7 +45,7 @@ class Conf(object):
return self._confobj.getboolean(section, option)
else:
return self._confobj.get(section, option)
except (configparser.NoOptionError, configparser.NoOptionError) as e:
except (configparser.NoOptionError, configparser.NoSectionError) as e:
raise ValueError(f'Option {option} does not exist in section {section}: {e}')
def set(self, option, value, section='userconfig'):