Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0663a1e

Browse files
committed
Let configparser use ordered dicts by default.
1 parent 6accb98 commit 0663a1e

3 files changed

Lines changed: 13 additions & 1 deletion

File tree

Doc/library/configparser.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ write-back, as will be the keys within each section.
6464
options within a section, and for the default values. This class does not
6565
support the magical interpolation behavior.
6666

67+
.. versionchanged 3.1
68+
The default *dict_type* is :class:`collections.OrderedDict`.
69+
6770
6871
.. class:: ConfigParser([defaults[, dict_type]])
6972

@@ -80,6 +83,9 @@ write-back, as will be the keys within each section.
8083
option names to lower case), the values ``foo %(bar)s`` and ``foo %(BAR)s`` are
8184
equivalent.
8285

86+
.. versionchanged 3.1
87+
The default *dict_type* is :class:`collections.OrderedDict`.
88+
8389
8490
.. class:: SafeConfigParser([defaults[, dict_type]])
8591

@@ -90,6 +96,9 @@ write-back, as will be the keys within each section.
9096

9197
.. XXX Need to explain what's safer/more predictable about it.
9298
99+
.. versionchanged 3.1
100+
The default *dict_type* is :class:`collections.OrderedDict`.
101+
93102
94103
.. exception:: NoSectionError
95104

Lib/configparser.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
"""
8989

9090
import re
91+
from collections import OrderedDict
9192

9293
__all__ = ["NoSectionError", "DuplicateSectionError", "NoOptionError",
9394
"InterpolationError", "InterpolationDepthError",
@@ -215,7 +216,7 @@ def __init__(self, filename, lineno, line):
215216

216217

217218
class RawConfigParser:
218-
def __init__(self, defaults=None, dict_type=dict):
219+
def __init__(self, defaults=None, dict_type=OrderedDict):
219220
self._dict = dict_type
220221
self._sections = self._dict()
221222
self._defaults = self._dict()

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ Library
179179

180180
- The _asdict() for method for namedtuples now returns an OrderedDict().
181181

182+
- configparser now defaults to using an ordered dictionary.
183+
182184
- Issue #1733986: Fixed mmap crash in accessing elements of second map object
183185
with same tagname but larger size than first map. (Windows)
184186

0 commit comments

Comments
 (0)