[Python-checkins] bpo-34003: Use dict instead of OrderedDict in csv.DictReader (GH-8014)
Raymond Hettinger
webhook-mailer at python.org
Thu Jan 31 03:47:56 EST 2019
https://github.com/python/cpython/commit/9f3f0931cfc58498086d287226650599a97412bb
commit: 9f3f0931cfc58498086d287226650599a97412bb
branch: master
author: Michael Selik <mike at selik.org>
committer: Raymond Hettinger <rhettinger at users.noreply.github.com>
date: 2019-01-31T00:47:53-08:00
summary:
bpo-34003: Use dict instead of OrderedDict in csv.DictReader (GH-8014)
files:
A Misc/NEWS.d/next/Library/2018-06-29-13-05-01.bpo-34003.Iu831h.rst
M Doc/library/csv.rst
M Lib/csv.py
diff --git a/Doc/library/csv.rst b/Doc/library/csv.rst
index 049537eff898..17534fcc4615 100644
--- a/Doc/library/csv.rst
+++ b/Doc/library/csv.rst
@@ -150,12 +150,12 @@ The :mod:`csv` module defines the following classes:
dialect='excel', *args, **kwds)
Create an object that operates like a regular reader but maps the
- information in each row to an :mod:`OrderedDict <collections.OrderedDict>`
- whose keys are given by the optional *fieldnames* parameter.
+ information in each row to a :class:`dict` whose keys are given by the
+ optional *fieldnames* parameter.
The *fieldnames* parameter is a :term:`sequence`. If *fieldnames* is
omitted, the values in the first row of file *f* will be used as the
- fieldnames. Regardless of how the fieldnames are determined, the ordered
+ fieldnames. Regardless of how the fieldnames are determined, the
dictionary preserves their original ordering.
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:
All other optional or keyword arguments are passed to the underlying
:class:`reader` instance.
- .. versionchanged:: 3.6
- Returned rows are now of type :class:`OrderedDict`.
+ .. versionchanged:: 3.8
+ Returned rows are now of type :class:`dict`.
A short usage example::
@@ -181,7 +181,7 @@ The :mod:`csv` module defines the following classes:
John Cleese
>>> print(row)
- OrderedDict([('first_name', 'John'), ('last_name', 'Cleese')])
+ {'first_name': 'John', 'last_name': 'Cleese'}
.. class:: DictWriter(f, fieldnames, restval='', extrasaction='raise', \
diff --git a/Lib/csv.py b/Lib/csv.py
index 58624af90534..eeeedabc6bb8 100644
--- a/Lib/csv.py
+++ b/Lib/csv.py
@@ -11,7 +11,6 @@
__doc__
from _csv import Dialect as _Dialect
-from collections import OrderedDict
from io import StringIO
__all__ = ["QUOTE_MINIMAL", "QUOTE_ALL", "QUOTE_NONNUMERIC", "QUOTE_NONE",
@@ -117,7 +116,7 @@ def __next__(self):
# values
while row == []:
row = next(self.reader)
- d = OrderedDict(zip(self.fieldnames, row))
+ d = dict(zip(self.fieldnames, row))
lf = len(self.fieldnames)
lr = len(row)
if lf < lr:
diff --git a/Misc/NEWS.d/next/Library/2018-06-29-13-05-01.bpo-34003.Iu831h.rst b/Misc/NEWS.d/next/Library/2018-06-29-13-05-01.bpo-34003.Iu831h.rst
new file mode 100644
index 000000000000..7bc5e1200ae8
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2018-06-29-13-05-01.bpo-34003.Iu831h.rst
@@ -0,0 +1,2 @@
+csv.DictReader now creates dicts instead of OrderedDicts. Patch by Michael
+Selik.
More information about the Python-checkins
mailing list