This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: configparser should use dict instead of OrderedDict in 3.7+
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: eric.smith, jreese, lukasz.langa, methane, rhettinger, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2018-05-14 18:18 by jreese, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 6819 merged jreese, 2018-05-14 18:59
PR 11712 merged methane, 2019-01-31 08:16
PR 11712 merged methane, 2019-01-31 08:16
PR 11712 merged methane, 2019-01-31 08:16
Messages (6)
msg316547 - (view) Author: John Reese (jreese) * Date: 2018-05-14 18:18
The configparser module uses `collections.OrderedDict` as its default, but this is no longer necessary in 3.7+ due to the semantics of core dictionaries being ordered by design.  configparser should just use `dict` by default now, instead.
msg316550 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2018-05-14 18:55
Like #33463, it will require a deprecation cycle. I'm not sure it's worth the hassle, but I wouldn't oppose it if someone wanted to do the work. 3.8 would be the first version where it could be added.
msg316552 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-05-14 19:00
See msg308974 in issue32360.
msg316620 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2018-05-15 04:45
I am +1 to changing it to dict for Python 3.8.

This use case is different from `namedtuple._asdict`. The type of the dictionary is for the purpose of internal storage of the parser. Unlike `namedtuple._asdict`, it is not exposed to the user.

The purpose of changing the default to OrderedDict in the past is not documented but implying from its properties we can deduce it was to make minimal edits to .ini files stable. This property will remain unchanged with changing the type back to `dict`.

The history here is this:
- a `dict_type` was introduced by MvL in r52908 (issue 1371075) with the motivation to allow sorting or order preservation (December 2006);
- the default `dict_type` was changed by Raymond to OrderedDict for 3.1 in 0663a1ed793c164fb11d3dd62bebc677e260891e (March 2009); as far as I can tell there was no issue for it when that change was made.

I acknowledge that in https://bugs.python.org/issue32360 Raymond states that "can't just change the default argument for configparser" but I don't see why. ConfigParser doesn't return the dictionary to the user in any API and the new 3.6+ dictionary preserves order just as OrderedDict.
msg318790 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2018-06-05 23:31
New changeset 3a5b0d8988491d9408b22bceea6fd70b91345724 by Łukasz Langa (John Reese) in branch 'master':
bpo-33504: Migrate configparser from OrderedDict to dict. (#6819)
https://github.com/python/cpython/commit/3a5b0d8988491d9408b22bceea6fd70b91345724
msg334615 - (view) Author: Inada Naoki (methane) * (Python committer) Date: 2019-01-31 08:53
New changeset 0897e0c597c065f043e4286d01f16f473ab664ee by Inada Naoki in branch 'master':
bpo-33504: fix wrong "versionchanged" (GH-11712)
https://github.com/python/cpython/commit/0897e0c597c065f043e4286d01f16f473ab664ee
History
Date User Action Args
2022-04-11 14:59:00adminsetgithub: 77685
2019-01-31 08:53:52methanesetnosy: + methane
messages: + msg334615
2019-01-31 08:17:09methanesetpull_requests: + pull_request11572
2019-01-31 08:16:57methanesetpull_requests: + pull_request11571
2019-01-31 08:16:48methanesetpull_requests: + pull_request11570
2018-06-05 23:33:57lukasz.langasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2018-06-05 23:31:36lukasz.langasetmessages: + msg318790
2018-05-15 04:45:31lukasz.langasetmessages: + msg316620
2018-05-14 19:05:46jreesesetnosy: + lukasz.langa
2018-05-14 19:00:04serhiy.storchakasetnosy: + rhettinger, serhiy.storchaka
messages: + msg316552
2018-05-14 18:59:08jreesesetkeywords: + patch
stage: patch review
pull_requests: + pull_request6504
2018-05-14 18:55:39eric.smithsetnosy: + eric.smith

messages: + msg316550
versions: - Python 3.7
2018-05-14 18:18:18jreesecreate