Skip to content

Commit c740736

Browse files
gh-100989: Improve the accuracy of collections.deque docstrings (#100990)
Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
1 parent c24f1f1 commit c740736

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

Modules/_collectionsmodule.c

+24-13
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,9 @@ deque_rotate(dequeobject *deque, PyObject *const *args, Py_ssize_t nargs)
910910
}
911911

912912
PyDoc_STRVAR(rotate_doc,
913-
"Rotate the deque n steps to the right (default n=1). If n is negative, rotates left.");
913+
"rotate(n)\n\n"
914+
"Rotate the deque *n* steps to the right (default ``n=1``). "
915+
"If *n* is negative, rotates left.");
914916

915917
static PyObject *
916918
deque_reverse(dequeobject *deque, PyObject *unused)
@@ -951,7 +953,8 @@ deque_reverse(dequeobject *deque, PyObject *unused)
951953
}
952954

953955
PyDoc_STRVAR(reverse_doc,
954-
"D.reverse() -- reverse *IN PLACE*");
956+
"reverse()\n\n"
957+
"Reverse the elements of the deque *IN PLACE*.");
955958

956959
static PyObject *
957960
deque_count(dequeobject *deque, PyObject *v)
@@ -990,7 +993,8 @@ deque_count(dequeobject *deque, PyObject *v)
990993
}
991994

992995
PyDoc_STRVAR(count_doc,
993-
"D.count(value) -> integer -- return number of occurrences of value");
996+
"count(x) -> int\n\n"
997+
"Count the number of deque elements equal to *x*.");
994998

995999
static int
9961000
deque_contains(dequeobject *deque, PyObject *v)
@@ -1098,8 +1102,10 @@ deque_index(dequeobject *deque, PyObject *const *args, Py_ssize_t nargs)
10981102
}
10991103

11001104
PyDoc_STRVAR(index_doc,
1101-
"D.index(value, [start, [stop]]) -> integer -- return first index of value.\n"
1102-
"Raises ValueError if the value is not present.");
1105+
"index(x, [start, [stop]]) -> int\n\n"
1106+
"Return the position of *x* in the deque "
1107+
"(at or after index *start* and before index *stop*). "
1108+
"Returns the first match or raises a ValueError if not found.");
11031109

11041110
/* insert(), remove(), and delitem() are implemented in terms of
11051111
rotate() for simplicity and reasonable performance near the end
@@ -1144,10 +1150,13 @@ deque_insert(dequeobject *deque, PyObject *const *args, Py_ssize_t nargs)
11441150
}
11451151

11461152
PyDoc_STRVAR(insert_doc,
1147-
"D.insert(index, object) -- insert object before index");
1153+
"insert(i, x)\n\n"
1154+
"Insert *x* into the deque at position *i*.");
11481155

11491156
PyDoc_STRVAR(remove_doc,
1150-
"D.remove(value) -- remove first occurrence of value.");
1157+
"remove(x)\n\n"
1158+
"Remove the first occurrence of *x*."
1159+
"If not found, raises a ValueError.");
11511160

11521161
static int
11531162
valid_index(Py_ssize_t i, Py_ssize_t limit)
@@ -1518,7 +1527,8 @@ deque_sizeof(dequeobject *deque, void *unused)
15181527
}
15191528

15201529
PyDoc_STRVAR(sizeof_doc,
1521-
"D.__sizeof__() -- size of D in memory, in bytes");
1530+
"__sizeof__() -> int\n\n"
1531+
"Size of the deque in memory, in bytes.");
15221532

15231533
static PyObject *
15241534
deque_get_maxlen(dequeobject *deque, void *Py_UNUSED(ignored))
@@ -1553,7 +1563,8 @@ static PySequenceMethods deque_as_sequence = {
15531563
static PyObject *deque_iter(dequeobject *deque);
15541564
static PyObject *deque_reviter(dequeobject *deque, PyObject *Py_UNUSED(ignored));
15551565
PyDoc_STRVAR(reversed_doc,
1556-
"D.__reversed__() -- return a reverse iterator over the deque");
1566+
"__reversed__()\n\n"
1567+
"Return a reverse iterator over the deque.");
15571568

15581569
static PyMethodDef deque_methods[] = {
15591570
{"append", (PyCFunction)deque_append,
@@ -1598,9 +1609,8 @@ static PyMethodDef deque_methods[] = {
15981609
};
15991610

16001611
PyDoc_STRVAR(deque_doc,
1601-
"deque([iterable[, maxlen]]) --> deque object\n\
1602-
\n\
1603-
A list-like sequence optimized for data accesses near its endpoints.");
1612+
"deque([iterable[, maxlen]]) -> collections.deque\n\n"
1613+
"A list-like sequence optimized for data accesses near its endpoints.");
16041614

16051615
static PyTypeObject deque_type = {
16061616
PyVarObject_HEAD_INIT(NULL, 0)
@@ -1979,7 +1989,8 @@ new_defdict(defdictobject *dd, PyObject *arg)
19791989
dd->default_factory ? dd->default_factory : Py_None, arg, NULL);
19801990
}
19811991

1982-
PyDoc_STRVAR(defdict_copy_doc, "D.copy() -> a shallow copy of D.");
1992+
PyDoc_STRVAR(defdict_copy_doc, "copy() -> collections.deque\n\n"
1993+
"A shallow copy of the deque.");
19831994

19841995
static PyObject *
19851996
defdict_copy(defdictobject *dd, PyObject *Py_UNUSED(ignored))

0 commit comments

Comments
 (0)