Skip to content

Commit

Permalink
Let configparser use ordered dicts by default.
Browse files Browse the repository at this point in the history
  • Loading branch information
rhettinger committed Mar 2, 2009
1 parent 6accb98 commit 0663a1e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
9 changes: 9 additions & 0 deletions Doc/library/configparser.rst
Expand Up @@ -64,6 +64,9 @@ write-back, as will be the keys within each section.
options within a section, and for the default values. This class does not
support the magical interpolation behavior.

.. versionchanged 3.1
The default *dict_type* is :class:`collections.OrderedDict`.
.. class:: ConfigParser([defaults[, dict_type]])

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

.. versionchanged 3.1
The default *dict_type* is :class:`collections.OrderedDict`.
.. class:: SafeConfigParser([defaults[, dict_type]])

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

.. XXX Need to explain what's safer/more predictable about it.
.. versionchanged 3.1
The default *dict_type* is :class:`collections.OrderedDict`.
.. exception:: NoSectionError

Expand Down
3 changes: 2 additions & 1 deletion Lib/configparser.py
Expand Up @@ -88,6 +88,7 @@
"""

import re
from collections import OrderedDict

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


class RawConfigParser:
def __init__(self, defaults=None, dict_type=dict):
def __init__(self, defaults=None, dict_type=OrderedDict):
self._dict = dict_type
self._sections = self._dict()
self._defaults = self._dict()
Expand Down
2 changes: 2 additions & 0 deletions Misc/NEWS
Expand Up @@ -179,6 +179,8 @@ Library

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

- configparser now defaults to using an ordered dictionary.

- Issue #1733986: Fixed mmap crash in accessing elements of second map object
with same tagname but larger size than first map. (Windows)

Expand Down

0 comments on commit 0663a1e

Please sign in to comment.