Skip to content

Order of configparser.ConfigParser.read() arguments #96765

Closed
@DimitriPapadopoulos

Description

@DimitriPapadopoulos

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc direasy

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions