--remember-answers converts values of type NoneType to str and writes the string 'None' to the config file .mrbob.ini.
This causes problems when using the answers file in non-interactive mode with the option --config. The ConfigParser only reads strings and reads the string 'None' as a str and not as a NoneType as we would expect.
|
def write_config(fs_config, section, data): |
|
parser = configparser.ConfigParser(dict_type=OrderedDict) |
|
parser.add_section(section) |
|
for key, value in data.items(): |
|
if not isinstance(value, six.string_types): |
|
value = str(value) |
|
|
|
if not six.PY3: # pragma: no cover |
|
value = value.encode("utf-8") |
|
parser.set(section, key, value) |
|
with open(fs_config, "w") as f: |
|
parser.write(f) |
One possible solution could be not to convert values of type NoneType to str and let them as None.
The RawConfigParser already writes only non None values and it changes None values to empty strings:
https://github.com/python/cpython/blob/605022aeb69ae19cae1c020a6993ab5c433ce907/Lib/configparser.py#L978-L991
if value is not None or not self._allow_no_value:
value = delimiter + str(value).replace('\n', '\n\t')
else:
value = ""
--remember-answersconverts values of typeNoneTypetostrand writes the string'None'to the config file.mrbob.ini.This causes problems when using the answers file in non-interactive mode with the option
--config. The ConfigParser only reads strings and reads the string'None'as astrand not as aNoneTypeas we would expect.mr.bob/mrbob/parsing.py
Lines 87 to 98 in ccc91b4
One possible solution could be not to convert values of type
NoneTypetostrand let them asNone.The
RawConfigParseralready writes only nonNonevalues and it changesNonevalues to empty strings:https://github.com/python/cpython/blob/605022aeb69ae19cae1c020a6993ab5c433ce907/Lib/configparser.py#L978-L991