csv.Dialect: Defaults are documented but not correctly implemented
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 25/100
Research direction
Start with the csv.py entry points for csv.Dialect and csv.excel, then run the reproducer from the issue to observe the current defaults and error. Done means the documented Dialect defaults behave as described without breaking existing csv behavior; gh-100336 is already linked as work on this issue.
Written by the indexing model from the issue text.
Description
Bug report
In gh-68335, it was reported that the default values for csv.Dialect were not documented properly. They are, as pointed out by @smontanaro there, at https://docs.python.org/2/library/csv.html#dialects-and-formatting-parameters -- and still are for Python 3.11.
However, while I was attempting to fix gh-73138, I discovered that all arguments of csv.Dialect are None and even trigger unexpected behavior (if following the documentation):
import csv
class mydialect(csv.Dialect):
quotechar = ":"
mydialect()
raises a _csv.Error caused by a TypeError, instead of using the documented default delimiter ,.
Traceback (most recent call last):
File "/opt/homebrew/Cellar/python@3.11/3.11.0/Frameworks/Python.framework/Versions/3.11/lib/python3.11/csv.py", line 49, in _validate
_Dialect(self)
TypeError: "delimiter" must be string, not NoneType
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/homebrew/Cellar/python@3.11/3.11.0/Frameworks/Python.framework/Versions/3.11/lib/python3.11/csv.py", line 45, in __init__
self._validate()
File "/opt/homebrew/Cellar/python@3.11/3.11.0/Frameworks/Python.framework/Versions/3.11/lib/python3.11/csv.py", line 52, in _validate
raise Error(str(e))
_csv.Error: "delimiter" must be string, not NoneType
The discrepancy is, that the documented default values are not for the csv.Dialect class, but for its child csv.excel.
In gh-96842, a fix was prepared, improving the documentation to point this out.
I think a better fix would be to actually add the proper default values as they are written in the documentation.
The updated documentation in gh-96842 might be easily missed, and developers implementing a csv.Dialect would expect the defaults to be as documented, not as the csv.excel has them (if they want to inherit from csv.excel, they can still do so explicitly).
Your environment
- CPython versions tested on: Python 3.10, 3.11, and from the main branch `Python 3.12.0a3+
- Operating system and architecture: MacOS arm
Linked PRs
- gh-100336
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 36k
- Avg merge
- 1d 9h
- Merged PRs (30d)
- 558
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from python/cpython
-
docs pending
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
stdlib type-feature
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
stdlib type-feature
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
build type-bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
stdlib topic-email type-feature
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
Similar issues
-
🐛 Bug 🔔 Pending processing
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
jumpserver/jumpserver#17584 ·
-
link-check link-check:sphinx-theme
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
modelscope/DiffSynth-Studio#1702 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
qgis/QGIS-Documentation#11275 ·
-
bug priority:normal ready-for-dev
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
OpenHands/extensions#626 · 1 comment ·