You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ConfigParser parsing failures with default_section and ExtendedInterpolation options #71018
ConfigParser(interpolation=ExtendedInterpolation) fails with strange error:
Traceback (most recent call last):
File "configparser-test.py", line 36, in <module>
print_sections(cp)
File "configparser-test.py", line 21, in print_sections
cp.read_string(__doc__)
File "/usr/lib64/python3.4/configparser.py", line 696, in read_stringself.read_file(sfile, source)
File "/usr/lib64/python3.4/configparser.py", line 691, in read_fileself._read(f, source)
File "/usr/lib64/python3.4/configparser.py", line 1089, in _readself._join_multiline_values()
File "/usr/lib64/python3.4/configparser.py", line 1101, in _join_multiline_values
name, val)
TypeError: before_read() missing 1 required positional argument: 'value'
I think there is some misunderstanding of what default_section is supposed to do, in fact in provides default values for *other* section, as the documentation says, it doesn't mangle section separation.
In case of ExtendedInterpolation, the interpolation argument needs to be instantiated, i.e. the call should be:
ConfigParser(interpolation=ExtendedInterpolation())
Note: the problem here was due to passing ExtendedInterpolation (the class) instead of ExtendedInterpolation() (the object). This is now fixed through BPO-41086.
Activity
frispete commentedon Apr 22, 2016
ConfigParser fails in interesting ways, when using default_section and ExtendedInterpolation options. Running the attached script results in:
ConfigParser() with expected result:
global: [('loglevel', 'WARNING'), ('logfile', '-')]
section1: [('key_a', 'value'), ('key_b', 'morevalue')]
section2: [('key_c', 'othervalue'), ('key_d', 'differentvalue')]
ConfigParser(default_section='global') mangles section separation:
section1: [('loglevel', 'WARNING'), ('logfile', '-'), ('key_a', 'value'), ('key_b', 'morevalue')]
section2: [('loglevel', 'WARNING'), ('logfile', '-'), ('key_c', 'othervalue'), ('key_d', 'differentvalue')]
while it is expected to behave identical.
SilentGhost commentedon Apr 23, 2016
I think there is some misunderstanding of what default_section is supposed to do, in fact in provides default values for *other* section, as the documentation says, it doesn't mangle section separation.
In case of ExtendedInterpolation, the interpolation argument needs to be instantiated, i.e. the call should be:
ConfigParser(interpolation=ExtendedInterpolation())
ambv commentedon Feb 17, 2022
Note: the problem here was due to passing
ExtendedInterpolation(the class) instead ofExtendedInterpolation()(the object). This is now fixed through BPO-41086.