Closed
Description
Bug report
When multiple INI configuration files with identical section(s) and key(s) are fed to configparser.ConfigParser.read
, the result is undefined / not documented. Actually the last file containing a given section/key takes precedence over previous files, as I would have expected from a straightforward implementation. However:
- This behaviour should be documented.
Perhaps this behaviour should be changed, and the first file take precedence over subsequent files. In practice that would break compatibility, but since the result is currently undocumented, that may be OK.
Example
Here are two INI files:
1.ini
[section]
a = 1
b = "11"
2.ini
[section]
a = 2
b = "22"
And here is the order of the filenames changes the result:
>>> import sys
>>> import configparser
>>> config = configparser.ConfigParser()
>>>
>>> config.read(["1.ini", "2.ini"])
['1.ini', '2.ini']
>>> config.write(sys.stdout)
[section]
a = 2
b = "22"
>>>
>>> config.read(["2.ini", "1.ini"])
['2.ini', '1.ini']
>>> config.write(sys.stdout)
[section]
a = 1
b = "11"
>>>
Your environment
- CPython versions tested on: 3.6.9
- Operating system and architecture: Ubuntu 18.04
Linked PRs
- gh-96765 Add docs order of configparser.ConfigParser.read() arguments #107683
- gh-96765: Update ConfigParser.read() docs with multi-file read example #121664
- [3.13] gh-96765: Update ConfigParser.read() docs with multi-file read example (GH-121664) #121687
- [3.12] gh-96765: Update ConfigParser.read() docs with multi-file read example (GH-121664) #121688