Update fallback option and ensure list is returned

This commit is contained in:
Eric Torres
2019-04-18 21:44:38 -07:00
parent 250ce3d945
commit 3fb3cbede8

View File

@@ -53,11 +53,14 @@ def load_list_from_option(parser, *, section="", option="", fallback=None):
:returns: the list parsed by JSON :returns: the list parsed by JSON
:param fallback: the fallback value to return if the option is empty :param fallback: the fallback value to return if the option is empty
:type fallback: list :type fallback: list
:rtype: list or type of fallback value :rtype: list
""" """
try: try:
return json.loads(parser[section][option]) return json.loads(parser[section][option])
except (json.decoder.JSONDecodeError, KeyError): except (json.decoder.JSONDecodeError, KeyError):
if fallback is None:
return []
else:
return fallback return fallback