Skip to content

Commit 2a3a357

Browse files
ctrlaltdelmjs
authored andcommitted
Fix config file parsing for None attributes (mjs#393)
Previously it was failing with the following exception when a default attribute was set to None. $ python3 livetest.py livetest-sample.ini livetest.py:11: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses import imp Traceback (most recent call last): File "livetest.py", line 1096, in <module> main() File "livetest.py", line 1069, in main host_config = parse_argv() File "livetest.py", line 1055, in parse_argv host_config = parse_config_file(ini_path) File "/home/user/dev/imapclient/imapclient/config.py", line 47, in parse_config_file parser = SafeConfigParser(get_string_config_defaults()) File "/usr/lib/python3.7/configparser.py", line 1225, in __init__ super().__init__(*args, **kwargs) File "/usr/lib/python3.7/configparser.py", line 638, in __init__ self._read_defaults(defaults) File "/usr/lib/python3.7/configparser.py", line 1216, in _read_defaults self.read_dict({self.default_section: defaults}) File "/usr/lib/python3.7/configparser.py", line 753, in read_dict self.set(section, key, value) File "/usr/lib/python3.7/configparser.py", line 1197, in set self._validate_value_types(option=option, value=value) File "/usr/lib/python3.7/configparser.py", line 1182, in _validate_value_types raise TypeError("option values must be strings") TypeError: option values must be strings Closes mjs#392.
1 parent fd86aca commit 2a3a357

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

imapclient/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ def get_string_config_defaults():
6666
v = 'true'
6767
elif v is False:
6868
v = 'false'
69+
elif not v:
70+
v = ''
6971
out[k] = v
7072
return out
7173

livetest-sample.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# run "live" tests. These files are also supported by IMAPClient's
55
# interactive shell.
66

7-
[main]
7+
[DEFAULT]
88
host = <host>
99
username = <user>
1010
password = <password>

0 commit comments

Comments
 (0)