Skip to content

Commit 72abb8c

Browse files
smontanaroAA-Turnermerwok
authored
gh-114123: Migrate docstring from _csv to csv (#114124)
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com> Co-authored-by: Éric <merwok@netwok.org>
1 parent 68a7b78 commit 72abb8c

File tree

4 files changed

+78
-79
lines changed

4 files changed

+78
-79
lines changed

Lib/csv.py

+69-7
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,90 @@
11

2-
"""
3-
csv.py - read/write/investigate CSV files
2+
r"""
3+
CSV parsing and writing.
4+
5+
This module provides classes that assist in the reading and writing
6+
of Comma Separated Value (CSV) files, and implements the interface
7+
described by PEP 305. Although many CSV files are simple to parse,
8+
the format is not formally defined by a stable specification and
9+
is subtle enough that parsing lines of a CSV file with something
10+
like line.split(",") is bound to fail. The module supports three
11+
basic APIs: reading, writing, and registration of dialects.
12+
13+
14+
DIALECT REGISTRATION:
15+
16+
Readers and writers support a dialect argument, which is a convenient
17+
handle on a group of settings. When the dialect argument is a string,
18+
it identifies one of the dialects previously registered with the module.
19+
If it is a class or instance, the attributes of the argument are used as
20+
the settings for the reader or writer:
21+
22+
class excel:
23+
delimiter = ','
24+
quotechar = '"'
25+
escapechar = None
26+
doublequote = True
27+
skipinitialspace = False
28+
lineterminator = '\r\n'
29+
quoting = QUOTE_MINIMAL
30+
31+
SETTINGS:
32+
33+
* quotechar - specifies a one-character string to use as the
34+
quoting character. It defaults to '"'.
35+
* delimiter - specifies a one-character string to use as the
36+
field separator. It defaults to ','.
37+
* skipinitialspace - specifies how to interpret spaces which
38+
immediately follow a delimiter. It defaults to False, which
39+
means that spaces immediately following a delimiter is part
40+
of the following field.
41+
* lineterminator - specifies the character sequence which should
42+
terminate rows.
43+
* quoting - controls when quotes should be generated by the writer.
44+
It can take on any of the following module constants:
45+
46+
csv.QUOTE_MINIMAL means only when required, for example, when a
47+
field contains either the quotechar or the delimiter
48+
csv.QUOTE_ALL means that quotes are always placed around fields.
49+
csv.QUOTE_NONNUMERIC means that quotes are always placed around
50+
fields which do not parse as integers or floating point
51+
numbers.
52+
csv.QUOTE_STRINGS means that quotes are always placed around
53+
fields which are strings. Note that the Python value None
54+
is not a string.
55+
csv.QUOTE_NOTNULL means that quotes are only placed around fields
56+
that are not the Python value None.
57+
csv.QUOTE_NONE means that quotes are never placed around fields.
58+
* escapechar - specifies a one-character string used to escape
59+
the delimiter when quoting is set to QUOTE_NONE.
60+
* doublequote - controls the handling of quotes inside fields. When
61+
True, two consecutive quotes are interpreted as one during read,
62+
and when writing, each quote character embedded in the data is
63+
written as two quotes
464
"""
565

666
import re
767
import types
8-
from _csv import Error, __version__, writer, reader, register_dialect, \
68+
from _csv import Error, writer, reader, register_dialect, \
969
unregister_dialect, get_dialect, list_dialects, \
1070
field_size_limit, \
1171
QUOTE_MINIMAL, QUOTE_ALL, QUOTE_NONNUMERIC, QUOTE_NONE, \
12-
QUOTE_STRINGS, QUOTE_NOTNULL, \
13-
__doc__
72+
QUOTE_STRINGS, QUOTE_NOTNULL
1473
from _csv import Dialect as _Dialect
1574

1675
from io import StringIO
1776

1877
__all__ = ["QUOTE_MINIMAL", "QUOTE_ALL", "QUOTE_NONNUMERIC", "QUOTE_NONE",
1978
"QUOTE_STRINGS", "QUOTE_NOTNULL",
20-
"Error", "Dialect", "__doc__", "excel", "excel_tab",
79+
"Error", "Dialect", "excel", "excel_tab",
2180
"field_size_limit", "reader", "writer",
2281
"register_dialect", "get_dialect", "list_dialects", "Sniffer",
23-
"unregister_dialect", "__version__", "DictReader", "DictWriter",
82+
"unregister_dialect", "DictReader", "DictWriter",
2483
"unix_dialect"]
2584

85+
__version__ = "1.0"
86+
87+
2688
class Dialect:
2789
"""Describe a CSV dialect.
2890

Lib/test/test_csv.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1416,8 +1416,7 @@ def test_ordered_dict_reader(self):
14161416

14171417
class MiscTestCase(unittest.TestCase):
14181418
def test__all__(self):
1419-
extra = {'__doc__', '__version__'}
1420-
support.check__all__(self, csv, ('csv', '_csv'), extra=extra)
1419+
support.check__all__(self, csv, ('csv', '_csv'))
14211420

14221421
def test_subclassable(self):
14231422
# issue 44089
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Move the :mod:`csv` module docstring to the :mod:`!csv` module
2+
instead of reexporting it from the internal :mod:`!_csv` module,
3+
and remove ``__doc__`` from ``csv.__all__``.
4+
5+
Move :attr:`!csv.__version__` to the :mod:`!csv` module
6+
instead of reexporting it from the internal :mod:`!_csv` module,
7+
and remove ``__version__`` from ``csv.__all__``.

Modules/_csv.c

+1-70
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ module instead.
88
99
*/
1010

11-
#define MODULE_VERSION "1.0"
12-
1311
// clinic/_csv.c.h uses internal pycore_modsupport.h API
1412
#ifndef Py_BUILD_CORE_BUILTIN
1513
# define Py_BUILD_CORE_MODULE 1
@@ -1607,68 +1605,7 @@ PyType_Spec error_spec = {
16071605
* MODULE
16081606
*/
16091607

1610-
PyDoc_STRVAR(csv_module_doc,
1611-
"CSV parsing and writing.\n"
1612-
"\n"
1613-
"This module provides classes that assist in the reading and writing\n"
1614-
"of Comma Separated Value (CSV) files, and implements the interface\n"
1615-
"described by PEP 305. Although many CSV files are simple to parse,\n"
1616-
"the format is not formally defined by a stable specification and\n"
1617-
"is subtle enough that parsing lines of a CSV file with something\n"
1618-
"like line.split(\",\") is bound to fail. The module supports three\n"
1619-
"basic APIs: reading, writing, and registration of dialects.\n"
1620-
"\n"
1621-
"\n"
1622-
"DIALECT REGISTRATION:\n"
1623-
"\n"
1624-
"Readers and writers support a dialect argument, which is a convenient\n"
1625-
"handle on a group of settings. When the dialect argument is a string,\n"
1626-
"it identifies one of the dialects previously registered with the module.\n"
1627-
"If it is a class or instance, the attributes of the argument are used as\n"
1628-
"the settings for the reader or writer:\n"
1629-
"\n"
1630-
" class excel:\n"
1631-
" delimiter = ','\n"
1632-
" quotechar = '\"'\n"
1633-
" escapechar = None\n"
1634-
" doublequote = True\n"
1635-
" skipinitialspace = False\n"
1636-
" lineterminator = '\\r\\n'\n"
1637-
" quoting = QUOTE_MINIMAL\n"
1638-
"\n"
1639-
"SETTINGS:\n"
1640-
"\n"
1641-
" * quotechar - specifies a one-character string to use as the\n"
1642-
" quoting character. It defaults to '\"'.\n"
1643-
" * delimiter - specifies a one-character string to use as the\n"
1644-
" field separator. It defaults to ','.\n"
1645-
" * skipinitialspace - specifies how to interpret spaces which\n"
1646-
" immediately follow a delimiter. It defaults to False, which\n"
1647-
" means that spaces immediately following a delimiter is part\n"
1648-
" of the following field.\n"
1649-
" * lineterminator - specifies the character sequence which should\n"
1650-
" terminate rows.\n"
1651-
" * quoting - controls when quotes should be generated by the writer.\n"
1652-
" It can take on any of the following module constants:\n"
1653-
"\n"
1654-
" csv.QUOTE_MINIMAL means only when required, for example, when a\n"
1655-
" field contains either the quotechar or the delimiter\n"
1656-
" csv.QUOTE_ALL means that quotes are always placed around fields.\n"
1657-
" csv.QUOTE_NONNUMERIC means that quotes are always placed around\n"
1658-
" fields which do not parse as integers or floating point\n"
1659-
" numbers.\n"
1660-
" csv.QUOTE_STRINGS means that quotes are always placed around\n"
1661-
" fields which are strings. Note that the Python value None\n"
1662-
" is not a string.\n"
1663-
" csv.QUOTE_NOTNULL means that quotes are only placed around fields\n"
1664-
" that are not the Python value None.\n"
1665-
" csv.QUOTE_NONE means that quotes are never placed around fields.\n"
1666-
" * escapechar - specifies a one-character string used to escape\n"
1667-
" the delimiter when quoting is set to QUOTE_NONE.\n"
1668-
" * doublequote - controls the handling of quotes inside fields. When\n"
1669-
" True, two consecutive quotes are interpreted as one during read,\n"
1670-
" and when writing, each quote character embedded in the data is\n"
1671-
" written as two quotes\n");
1608+
PyDoc_STRVAR(csv_module_doc, "CSV parsing and writing.\n");
16721609

16731610
PyDoc_STRVAR(csv_reader_doc,
16741611
" csv_reader = reader(iterable [, dialect='excel']\n"
@@ -1741,12 +1678,6 @@ csv_exec(PyObject *module) {
17411678
return -1;
17421679
}
17431680

1744-
/* Add version to the module. */
1745-
if (PyModule_AddStringConstant(module, "__version__",
1746-
MODULE_VERSION) == -1) {
1747-
return -1;
1748-
}
1749-
17501681
/* Set the field limit */
17511682
module_state->field_limit = 128 * 1024;
17521683

0 commit comments

Comments
 (0)