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
Metadata
Metadata
Assignees
Projects
Status