I have a problem using the configparser
module.
import configparser
config = configparser.ConfigParser()
config.read_dict({"foo": {}})
foo = config["foo"]
foo.getboolean("missing_field")
I would like my code to raise an exception if the parsed configuration is missing a required field. However, getboolean()
returns None
in this case instead of raising a KeyError
as expected.
I could possibly use foo["missing_field"]
which does raise an exception. However, in such case, I loose the boolean conversion.
I could explicitly test for if res is None:
and throw the exception manually but I have a lot of config fields so that would be cumbersome.
Does Python provide an elegant way to force strict config parsing?