Skip to content

Commit 9f3f093

Browse files
selikrhettinger
authored andcommitted
bpo-34003: Use dict instead of OrderedDict in csv.DictReader (GH-8014)
1 parent a1f9a33 commit 9f3f093

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

Doc/library/csv.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,12 @@ The :mod:`csv` module defines the following classes:
150150
dialect='excel', *args, **kwds)
151151
152152
Create an object that operates like a regular reader but maps the
153-
information in each row to an :mod:`OrderedDict <collections.OrderedDict>`
154-
whose keys are given by the optional *fieldnames* parameter.
153+
information in each row to a :class:`dict` whose keys are given by the
154+
optional *fieldnames* parameter.
155155

156156
The *fieldnames* parameter is a :term:`sequence`. If *fieldnames* is
157157
omitted, the values in the first row of file *f* will be used as the
158-
fieldnames. Regardless of how the fieldnames are determined, the ordered
158+
fieldnames. Regardless of how the fieldnames are determined, the
159159
dictionary preserves their original ordering.
160160

161161
If a row has more fields than fieldnames, the remaining data is put in a
@@ -166,8 +166,8 @@ The :mod:`csv` module defines the following classes:
166166
All other optional or keyword arguments are passed to the underlying
167167
:class:`reader` instance.
168168

169-
.. versionchanged:: 3.6
170-
Returned rows are now of type :class:`OrderedDict`.
169+
.. versionchanged:: 3.8
170+
Returned rows are now of type :class:`dict`.
171171

172172
A short usage example::
173173

@@ -181,7 +181,7 @@ The :mod:`csv` module defines the following classes:
181181
John Cleese
182182

183183
>>> print(row)
184-
OrderedDict([('first_name', 'John'), ('last_name', 'Cleese')])
184+
{'first_name': 'John', 'last_name': 'Cleese'}
185185

186186

187187
.. class:: DictWriter(f, fieldnames, restval='', extrasaction='raise', \

Lib/csv.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
__doc__
1212
from _csv import Dialect as _Dialect
1313

14-
from collections import OrderedDict
1514
from io import StringIO
1615

1716
__all__ = ["QUOTE_MINIMAL", "QUOTE_ALL", "QUOTE_NONNUMERIC", "QUOTE_NONE",
@@ -117,7 +116,7 @@ def __next__(self):
117116
# values
118117
while row == []:
119118
row = next(self.reader)
120-
d = OrderedDict(zip(self.fieldnames, row))
119+
d = dict(zip(self.fieldnames, row))
121120
lf = len(self.fieldnames)
122121
lr = len(row)
123122
if lf < lr:
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
csv.DictReader now creates dicts instead of OrderedDicts. Patch by Michael
2+
Selik.

0 commit comments

Comments
 (0)