This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: CSV DictReader restval parameter documentation
Type: enhancement Stage: resolved
Components: Documentation Versions: Python 3.9, Python 3.8, Python 3.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Juhana.Jauhiainen, Moshe Sambol, docs@python, miss-islington, xtreak
Priority: normal Keywords: patch

Created on 2020-03-19 10:37 by Moshe Sambol, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 19099 merged Juhana.Jauhiainen, 2020-03-21 08:04
PR 19141 merged miss-islington, 2020-03-24 17:11
PR 19142 merged miss-islington, 2020-03-24 17:12
Messages (6)
msg364598 - (view) Author: Moshe Sambol (Moshe Sambol) Date: 2020-03-19 10:37
The csv.DictReader constructor takes two optional parameters, restkey and restval. restkey is documented well, but restval is not:

"If a row has more fields than fieldnames, the remaining data is put in a list and stored with the fieldname specified by restkey (which defaults to None). If a non-blank row has fewer fields than fieldnames, the missing values are filled-in with None."

Since restval is not mentioned here, the reader may assume that the next sentence applies to it:

"All other optional or keyword arguments are passed to the underlying reader instance."

But this is not the case for restval.

I suggest that the text be amended to 

"If a non-blank row has fewer fields than fieldnames, the missing values are filled-in with the value of restval (which defaults to None)."
msg364729 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2020-03-21 07:44
This looks like a good clarification to me where None is clarified that it's the value of restval. DictWriter has a similar doc "The optional restval parameter specifies the value to be written if the dictionary is missing a key in fieldnames" at https://docs.python.org/3/library/csv.html#csv.DictWriter
msg364948 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2020-03-24 17:11
New changeset 4b3252cb764807fdb3a661b458d43e4af55cf4df by Juhana Jauhiainen in branch 'master':
bpo-40013: Clarify documentation of restval in csv.DictReader (GH-19099)
https://github.com/python/cpython/commit/4b3252cb764807fdb3a661b458d43e4af55cf4df
msg364980 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2020-03-25 07:01
New changeset 2227c1a4ca87034ed9eac55eb260a5fb0a04375d by Miss Islington (bot) in branch '3.8':
bpo-40013: Clarify documentation of restval in csv.DictReader (GH-19099) (GH-19141)
https://github.com/python/cpython/commit/2227c1a4ca87034ed9eac55eb260a5fb0a04375d
msg364981 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2020-03-25 07:01
New changeset e5527f0edf7edc98e5e859b5fe823878684b4b6a by Miss Islington (bot) in branch '3.7':
bpo-40013: Clarify documentation of restval in csv.DictReader (GH-19099) (GH-19142)
https://github.com/python/cpython/commit/e5527f0edf7edc98e5e859b5fe823878684b4b6a
msg364982 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2020-03-25 07:05
Closing this as fixed. Thanks Moshe for the report.
History
Date User Action Args
2022-04-11 14:59:28adminsetgithub: 84194
2020-03-25 07:05:19xtreaksetstatus: open -> closed

title: CSV DictReader parameter documentation -> CSV DictReader restval parameter documentation
messages: + msg364982
versions: - Python 3.5, Python 3.6
type: enhancement
resolution: fixed
stage: patch review -> resolved
2020-03-25 07:01:18xtreaksetmessages: + msg364981
2020-03-25 07:01:01xtreaksetmessages: + msg364980
2020-03-24 17:12:03miss-islingtonsetpull_requests: + pull_request18503
2020-03-24 17:11:56miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request18502
2020-03-24 17:11:46xtreaksetmessages: + msg364948
2020-03-21 08:04:31Juhana.Jauhiainensetkeywords: + patch
nosy: + Juhana.Jauhiainen

pull_requests: + pull_request18459
stage: patch review
2020-03-21 07:44:34xtreaksetnosy: + xtreak
messages: + msg364729
2020-03-19 10:37:30Moshe Sambolcreate