Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit aacfa95

Browse files
committed
Issue #8973: Improve struct module docstrings.
1 parent d80a8ee commit aacfa95

1 file changed

Lines changed: 37 additions & 22 deletions

File tree

Modules/_struct.c

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1398,9 +1398,9 @@ s_unpack_internal(PyStructObject *soself, char *startfrom) {
13981398
PyDoc_STRVAR(s_unpack__doc__,
13991399
"S.unpack(buffer) -> (v1, v2, ...)\n\
14001400
\n\
1401-
Return tuple containing values unpacked according to this Struct's format.\n\
1402-
Requires len(buffer) == self.size. See struct.__doc__ for more on format\n\
1403-
strings.");
1401+
Return a tuple containing values unpacked according to the format\n\
1402+
string S.format. Requires len(buffer) == S.size. See help(struct)\n\
1403+
for more on format strings.");
14041404

14051405
static PyObject *
14061406
s_unpack(PyObject *self, PyObject *input)
@@ -1426,12 +1426,11 @@ s_unpack(PyObject *self, PyObject *input)
14261426
}
14271427

14281428
PyDoc_STRVAR(s_unpack_from__doc__,
1429-
"S.unpack_from(buffer[, offset]) -> (v1, v2, ...)\n\
1429+
"S.unpack_from(buffer[, offset=0]) -> (v1, v2, ...)\n\
14301430
\n\
1431-
Return tuple containing values unpacked according to this Struct's format.\n\
1432-
Unlike unpack, unpack_from can unpack values from any object supporting\n\
1433-
the buffer API, not just str. Requires len(buffer[offset:]) >= self.size.\n\
1434-
See struct.__doc__ for more on format strings.");
1431+
Return a tuple containing values unpacked according to the format\n\
1432+
string S.format. Requires len(buffer[offset:]) >= S.size. See\n\
1433+
help(struct) for more on format strings.");
14351434

14361435
static PyObject *
14371436
s_unpack_from(PyObject *self, PyObject *args, PyObject *kwds)
@@ -1566,8 +1565,9 @@ s_pack_internal(PyStructObject *soself, PyObject *args, int offset, char* buf)
15661565
PyDoc_STRVAR(s_pack__doc__,
15671566
"S.pack(v1, v2, ...) -> bytes\n\
15681567
\n\
1569-
Return a bytes containing values v1, v2, ... packed according to this\n\
1570-
Struct's format. See struct.__doc__ for more on format strings.");
1568+
Return a bytes object containing values v1, v2, ... packed according\n\
1569+
to the format string S.format. See help(struct) for more on format\n\
1570+
strings.");
15711571

15721572
static PyObject *
15731573
s_pack(PyObject *self, PyObject *args)
@@ -1603,10 +1603,10 @@ s_pack(PyObject *self, PyObject *args)
16031603
PyDoc_STRVAR(s_pack_into__doc__,
16041604
"S.pack_into(buffer, offset, v1, v2, ...)\n\
16051605
\n\
1606-
Pack the values v1, v2, ... according to this Struct's format, write \n\
1607-
the packed bytes into the writable buffer buf starting at offset. Note\n\
1608-
that the offset is not an optional argument. See struct.__doc__ for \n\
1609-
more on format strings.");
1606+
Pack the values v1, v2, ... according to the format string S.format\n\
1607+
and write the packed bytes into the writable buffer buf starting at\n\
1608+
offset. Note that the offset is not an optional argument. See\n\
1609+
help(struct) for more on format strings.");
16101610

16111611
static PyObject *
16121612
s_pack_into(PyObject *self, PyObject *args)
@@ -1781,7 +1781,9 @@ clearcache(PyObject *self)
17811781
}
17821782

17831783
PyDoc_STRVAR(calcsize_doc,
1784-
"Return size of C struct described by format string fmt.");
1784+
"calcsize(fmt) -> integer\n\
1785+
\n\
1786+
Return size in bytes of the struct described by the format string fmt.");
17851787

17861788
static PyObject *
17871789
calcsize(PyObject *self, PyObject *fmt)
@@ -1796,7 +1798,10 @@ calcsize(PyObject *self, PyObject *fmt)
17961798
}
17971799

17981800
PyDoc_STRVAR(pack_doc,
1799-
"Return bytes containing values v1, v2, ... packed according to fmt.");
1801+
"pack(fmt, v1, v2, ...) -> bytes\n\
1802+
\n\
1803+
Return a bytes object containing values v1, v2, ... packed according to\n\
1804+
the format string fmt. See help(struct) for more on format strings.");
18001805

18011806
static PyObject *
18021807
pack(PyObject *self, PyObject *args)
@@ -1825,8 +1830,12 @@ pack(PyObject *self, PyObject *args)
18251830
}
18261831

18271832
PyDoc_STRVAR(pack_into_doc,
1828-
"Pack the values v1, v2, ... according to fmt.\n\
1829-
Write the packed bytes into the writable buffer buf starting at offset.");
1833+
"pack_into(fmt, buffer, offset, v1, v2, ...)\n\
1834+
\n\
1835+
Pack the values v1, v2, ... according to the format string fmt and write\n\
1836+
the packed bytes into the writable buffer buf starting at offset. Note\n\
1837+
that the offset is not an optional argument. See help(struct) for more\n\
1838+
on format strings.");
18301839

18311840
static PyObject *
18321841
pack_into(PyObject *self, PyObject *args)
@@ -1855,8 +1864,11 @@ pack_into(PyObject *self, PyObject *args)
18551864
}
18561865

18571866
PyDoc_STRVAR(unpack_doc,
1858-
"Unpack the bytes containing packed C structure data, according to fmt.\n\
1859-
Requires len(bytes) == calcsize(fmt).");
1867+
"unpack(fmt, buffer) -> (v1, v2, ...)\n\
1868+
\n\
1869+
Return a tuple containing values unpacked according to the format string\n\
1870+
fmt. Requires len(buffer) == calcsize(fmt). See help(struct) for more\n\
1871+
on format strings.");
18601872

18611873
static PyObject *
18621874
unpack(PyObject *self, PyObject *args)
@@ -1875,8 +1887,11 @@ unpack(PyObject *self, PyObject *args)
18751887
}
18761888

18771889
PyDoc_STRVAR(unpack_from_doc,
1878-
"Unpack the buffer, containing packed C structure data, according to\n\
1879-
fmt, starting at offset. Requires len(buffer[offset:]) >= calcsize(fmt).");
1890+
"unpack_from(fmt, buffer[, offset=0]) -> (v1, v2, ...)\n\
1891+
\n\
1892+
Return a tuple containing values unpacked according to the format string\n\
1893+
fmt. Requires len(buffer[offset:]) >= calcsize(fmt). See help(struct)\n\
1894+
for more on format strings.");
18801895

18811896
static PyObject *
18821897
unpack_from(PyObject *self, PyObject *args, PyObject *kwds)

0 commit comments

Comments
 (0)