Skip to content

Commit 7d473ff

Browse files
pythongh-137949: Fix and improve the csv functions docstrings
The csv.register_dialect() docstring no longer imply that it returns a dialect. All functions have now signatures.
1 parent d22a745 commit 7d473ff

File tree

2 files changed

+27
-42
lines changed

2 files changed

+27
-42
lines changed

Modules/_csv.c

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1574,13 +1574,11 @@ csv_writer(PyObject *module, PyObject *args, PyObject *keyword_args)
15741574
_csv.list_dialects
15751575
15761576
Return a list of all known dialect names.
1577-
1578-
names = csv.list_dialects()
15791577
[clinic start generated code]*/
15801578

15811579
static PyObject *
15821580
_csv_list_dialects_impl(PyObject *module)
1583-
/*[clinic end generated code: output=a5b92b215b006a6d input=8953943eb17d98ab]*/
1581+
/*[clinic end generated code: output=a5b92b215b006a6d input=ec58040aafd6a20a]*/
15841582
{
15851583
return PyDict_Keys(get_csv_state(module)->dialects);
15861584
}
@@ -1617,13 +1615,11 @@ _csv.unregister_dialect
16171615
name: object
16181616
16191617
Delete the name/dialect mapping associated with a string name.
1620-
1621-
csv.unregister_dialect(name)
16221618
[clinic start generated code]*/
16231619

16241620
static PyObject *
16251621
_csv_unregister_dialect_impl(PyObject *module, PyObject *name)
1626-
/*[clinic end generated code: output=0813ebca6c058df4 input=6b5c1557bf60c7e7]*/
1622+
/*[clinic end generated code: output=0813ebca6c058df4 input=e1cf81bfe3ba0f62]*/
16271623
{
16281624
_csvstate *module_state = get_csv_state(module);
16291625
int rc = PyDict_Pop(module_state->dialects, name, NULL);
@@ -1643,13 +1639,11 @@ _csv.get_dialect
16431639
name: object
16441640
16451641
Return the dialect instance associated with name.
1646-
1647-
dialect = csv.get_dialect(name)
16481642
[clinic start generated code]*/
16491643

16501644
static PyObject *
16511645
_csv_get_dialect_impl(PyObject *module, PyObject *name)
1652-
/*[clinic end generated code: output=aa988cd573bebebb input=edf9ddab32e448fb]*/
1646+
/*[clinic end generated code: output=aa988cd573bebebb input=74865c659dcb441f]*/
16531647
{
16541648
return get_dialect_from_registry(name, get_csv_state(module));
16551649
}
@@ -1661,15 +1655,13 @@ _csv.field_size_limit
16611655
16621656
Sets an upper limit on parsed fields.
16631657
1664-
csv.field_size_limit([limit])
1665-
16661658
Returns old limit. If limit is not given, no new limit is set and
16671659
the old limit is returned
16681660
[clinic start generated code]*/
16691661

16701662
static PyObject *
16711663
_csv_field_size_limit_impl(PyObject *module, PyObject *new_limit)
1672-
/*[clinic end generated code: output=f2799ecd908e250b input=cec70e9226406435]*/
1664+
/*[clinic end generated code: output=f2799ecd908e250b input=77db7485ee3ae90a]*/
16731665
{
16741666
_csvstate *module_state = get_csv_state(module);
16751667
Py_ssize_t old_limit = FT_ATOMIC_LOAD_SSIZE_RELAXED(module_state->field_limit);
@@ -1705,37 +1697,38 @@ PyType_Spec error_spec = {
17051697
PyDoc_STRVAR(csv_module_doc, "CSV parsing and writing.\n");
17061698

17071699
PyDoc_STRVAR(csv_reader_doc,
1708-
" csv_reader = reader(iterable [, dialect='excel']\n"
1709-
" [optional keyword args])\n"
1710-
" for row in csv_reader:\n"
1711-
" process(row)\n"
1700+
"reader($module, iterable, /, dialect='excel', **fmtparams)\n"
1701+
"--\n\n"
1702+
"Return a reader object that will process lines from the given iterable.\n"
17121703
"\n"
17131704
"The \"iterable\" argument can be any object that returns a line\n"
17141705
"of input for each iteration, such as a file object or a list. The\n"
1715-
"optional \"dialect\" parameter is discussed below. The function\n"
1706+
"optional \"dialect\" argument defines a CSV dialect. The function\n"
17161707
"also accepts optional keyword arguments which override settings\n"
17171708
"provided by the dialect.\n"
17181709
"\n"
17191710
"The returned object is an iterator. Each iteration returns a row\n"
17201711
"of the CSV file (which can span multiple input lines).\n");
17211712

17221713
PyDoc_STRVAR(csv_writer_doc,
1723-
" csv_writer = csv.writer(fileobj [, dialect='excel']\n"
1724-
" [optional keyword args])\n"
1725-
" for row in sequence:\n"
1726-
" csv_writer.writerow(row)\n"
1714+
"writer($module, fileobj, /, dialect='excel', **fmtparams)\n"
1715+
"--\n\n"
1716+
"Return a writer object that will write user data on the given file object.\n"
17271717
"\n"
1728-
" [or]\n"
1729-
"\n"
1730-
" csv_writer = csv.writer(fileobj [, dialect='excel']\n"
1731-
" [optional keyword args])\n"
1732-
" csv_writer.writerows(rows)\n"
1733-
"\n"
1734-
"The \"fileobj\" argument can be any object that supports the file API.\n");
1718+
"The \"fileobj\" argument can be any object that supports the file API.\n"
1719+
"The optional \"dialect\" argument defines a CSV dialect. The function\n"
1720+
"also accepts optional keyword arguments which override settings\n"
1721+
"provided by the dialect.\n");
17351722

17361723
PyDoc_STRVAR(csv_register_dialect_doc,
1737-
"Create a mapping from a string name to a dialect class.\n"
1738-
" dialect = csv.register_dialect(name[, dialect[, **fmtparams]])");
1724+
"register_dialect($module, name, /, dialect='excel', **fmtparams)\n"
1725+
"--\n\n"
1726+
"Create a mapping from a string name to a CVS dialect.\n"
1727+
"\n"
1728+
"The optional \"dialect\" argument specifies the base dialect instance\n"
1729+
"or the name of the registered dialect. The function also accepts\n"
1730+
"optional keyword arguments which override settings provided by the\n"
1731+
"dialect.\n");
17391732

17401733
static struct PyMethodDef csv_methods[] = {
17411734
{ "reader", _PyCFunction_CAST(csv_reader),

Modules/clinic/_csv.c.h

Lines changed: 4 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)