@@ -462,7 +462,8 @@ the :meth:`__init__` options:
462
462
463
463
Please note: there are ways to add a set of key-value pairs in a single
464
464
operation. When you use a regular dictionary in those operations, the order
465
- of the keys may be random. For example:
465
+ of the keys will be ordered because dict preserves order from Python 3.7.
466
+ For example:
466
467
467
468
.. doctest ::
468
469
@@ -477,41 +478,10 @@ the :meth:`__init__` options:
477
478
... ' bar' : ' y' ,
478
479
... ' baz' : ' z' }
479
480
... })
480
- >>> parser.sections() # doctest: +SKIP
481
- ['section3', 'section2', 'section1']
482
- >>> [option for option in parser[' section3' ]] # doctest: +SKIP
483
- ['baz', 'foo', 'bar']
484
-
485
- In these operations you need to use an ordered dictionary as well:
486
-
487
- .. doctest ::
488
-
489
- >>> from collections import OrderedDict
490
- >>> parser = configparser.ConfigParser()
491
- >>> parser.read_dict(
492
- ... OrderedDict((
493
- ... (' s1' ,
494
- ... OrderedDict((
495
- ... (' 1' , ' 2' ),
496
- ... (' 3' , ' 4' ),
497
- ... (' 5' , ' 6' ),
498
- ... ))
499
- ... ),
500
- ... (' s2' ,
501
- ... OrderedDict((
502
- ... (' a' , ' b' ),
503
- ... (' c' , ' d' ),
504
- ... (' e' , ' f' ),
505
- ... ))
506
- ... ),
507
- ... ))
508
- ... )
509
- >>> parser.sections() # doctest: +SKIP
510
- ['s1', 's2']
511
- >>> [option for option in parser[' s1' ]] # doctest: +SKIP
512
- ['1', '3', '5']
513
- >>> [option for option in parser[' s2' ].values()] # doctest: +SKIP
514
- ['b', 'd', 'f']
481
+ >>> parser.sections()
482
+ ['section1', 'section2', 'section3']
483
+ >>> [option for option in parser[' section3' ]]
484
+ ['foo', 'bar', 'baz']
515
485
516
486
* *allow_no_value *, default value: ``False ``
517
487
@@ -891,7 +861,7 @@ interpolation if an option used is not defined elsewhere. ::
891
861
ConfigParser Objects
892
862
--------------------
893
863
894
- .. class :: ConfigParser(defaults=None, dict_type=dict , allow_no_value=False, delimiters=('=', ':'), comment_prefixes=('#', ';'), inline_comment_prefixes=None, strict=True, empty_lines_in_values=True, default_section=configparser.DEFAULTSECT, interpolation=BasicInterpolation(), converters={})
864
+ .. class :: ConfigParser(defaults=None, dict_type=collections.OrderedDict , allow_no_value=False, delimiters=('=', ':'), comment_prefixes=('#', ';'), inline_comment_prefixes=None, strict=True, empty_lines_in_values=True, default_section=configparser.DEFAULTSECT, interpolation=BasicInterpolation(), converters={})
895
865
896
866
The main configuration parser. When *defaults * is given, it is initialized
897
867
into the dictionary of intrinsic defaults. When *dict_type * is given, it
@@ -953,10 +923,6 @@ ConfigParser Objects
953
923
providing consistent behavior across the parser: non-string
954
924
keys and values are implicitly converted to strings.
955
925
956
- .. versionchanged :: 3.7
957
- The default *dict_type * is :class: `dict `, since it now preserves
958
- insertion order.
959
-
960
926
.. method :: defaults()
961
927
962
928
Return a dictionary containing the instance-wide defaults.
@@ -1213,7 +1179,7 @@ ConfigParser Objects
1213
1179
RawConfigParser Objects
1214
1180
-----------------------
1215
1181
1216
- .. class :: RawConfigParser(defaults=None, dict_type=dict , \
1182
+ .. class :: RawConfigParser(defaults=None, dict_type=collections.OrderedDict , \
1217
1183
allow_no_value=False, *, delimiters=('=', ':'), \
1218
1184
comment_prefixes=('#', ';'), \
1219
1185
inline_comment_prefixes=None, strict=True, \
@@ -1226,10 +1192,6 @@ RawConfigParser Objects
1226
1192
names, and values via its unsafe ``add_section `` and ``set `` methods,
1227
1193
as well as the legacy ``defaults= `` keyword argument handling.
1228
1194
1229
- .. versionchanged :: 3.7
1230
- The default *dict_type * is :class: `dict `, since it now preserves
1231
- insertion order.
1232
-
1233
1195
.. note ::
1234
1196
Consider using :class: `ConfigParser ` instead which checks types of
1235
1197
the values to be stored internally. If you don't want interpolation, you
0 commit comments