Skip to content

Commit 100da7c

Browse files
miss-islingtontimobrembeckCAM-Gerlach
authored
gh-100989: Improve the accuracy of collections.deque docstrings (GH-100990)
(cherry picked from commit c740736) Co-authored-by: Timo Ludwig <[email protected]> Co-authored-by: C.A.M. Gerlach <[email protected]>
1 parent 3c2a7bb commit 100da7c

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

Modules/_collectionsmodule.c

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -920,7 +920,9 @@ deque_rotate(dequeobject *deque, PyObject *const *args, Py_ssize_t nargs)
920920
}
921921

922922
PyDoc_STRVAR(rotate_doc,
923-
"Rotate the deque n steps to the right (default n=1). If n is negative, rotates left.");
923+
"rotate(n)\n\n"
924+
"Rotate the deque *n* steps to the right (default ``n=1``). "
925+
"If *n* is negative, rotates left.");
924926

925927
static PyObject *
926928
deque_reverse(dequeobject *deque, PyObject *unused)
@@ -961,7 +963,8 @@ deque_reverse(dequeobject *deque, PyObject *unused)
961963
}
962964

963965
PyDoc_STRVAR(reverse_doc,
964-
"D.reverse() -- reverse *IN PLACE*");
966+
"reverse()\n\n"
967+
"Reverse the elements of the deque *IN PLACE*.");
965968

966969
static PyObject *
967970
deque_count(dequeobject *deque, PyObject *v)
@@ -1001,7 +1004,8 @@ deque_count(dequeobject *deque, PyObject *v)
10011004
}
10021005

10031006
PyDoc_STRVAR(count_doc,
1004-
"D.count(value) -> integer -- return number of occurrences of value");
1007+
"count(x) -> int\n\n"
1008+
"Count the number of deque elements equal to *x*.");
10051009

10061010
static int
10071011
deque_contains(dequeobject *deque, PyObject *v)
@@ -1110,8 +1114,10 @@ deque_index(dequeobject *deque, PyObject *const *args, Py_ssize_t nargs)
11101114
}
11111115

11121116
PyDoc_STRVAR(index_doc,
1113-
"D.index(value, [start, [stop]]) -> integer -- return first index of value.\n"
1114-
"Raises ValueError if the value is not present.");
1117+
"index(x, [start, [stop]]) -> int\n\n"
1118+
"Return the position of *x* in the deque "
1119+
"(at or after index *start* and before index *stop*). "
1120+
"Returns the first match or raises a ValueError if not found.");
11151121

11161122
/* insert(), remove(), and delitem() are implemented in terms of
11171123
rotate() for simplicity and reasonable performance near the end
@@ -1156,10 +1162,13 @@ deque_insert(dequeobject *deque, PyObject *const *args, Py_ssize_t nargs)
11561162
}
11571163

11581164
PyDoc_STRVAR(insert_doc,
1159-
"D.insert(index, object) -- insert object before index");
1165+
"insert(i, x)\n\n"
1166+
"Insert *x* into the deque at position *i*.");
11601167

11611168
PyDoc_STRVAR(remove_doc,
1162-
"D.remove(value) -- remove first occurrence of value.");
1169+
"remove(x)\n\n"
1170+
"Remove the first occurrence of *x*."
1171+
"If not found, raises a ValueError.");
11631172

11641173
static int
11651174
valid_index(Py_ssize_t i, Py_ssize_t limit)
@@ -1537,7 +1546,8 @@ deque_sizeof(dequeobject *deque, void *unused)
15371546
}
15381547

15391548
PyDoc_STRVAR(sizeof_doc,
1540-
"D.__sizeof__() -- size of D in memory, in bytes");
1549+
"__sizeof__() -> int\n\n"
1550+
"Size of the deque in memory, in bytes.");
15411551

15421552
static int
15431553
deque_bool(dequeobject *deque)
@@ -1592,7 +1602,8 @@ static PyNumberMethods deque_as_number = {
15921602
static PyObject *deque_iter(dequeobject *deque);
15931603
static PyObject *deque_reviter(dequeobject *deque, PyObject *Py_UNUSED(ignored));
15941604
PyDoc_STRVAR(reversed_doc,
1595-
"D.__reversed__() -- return a reverse iterator over the deque");
1605+
"__reversed__()\n\n"
1606+
"Return a reverse iterator over the deque.");
15961607

15971608
static PyMethodDef deque_methods[] = {
15981609
{"append", (PyCFunction)deque_append,
@@ -1637,9 +1648,8 @@ static PyMethodDef deque_methods[] = {
16371648
};
16381649

16391650
PyDoc_STRVAR(deque_doc,
1640-
"deque([iterable[, maxlen]]) --> deque object\n\
1641-
\n\
1642-
A list-like sequence optimized for data accesses near its endpoints.");
1651+
"deque([iterable[, maxlen]]) -> collections.deque\n\n"
1652+
"A list-like sequence optimized for data accesses near its endpoints.");
16431653

16441654
static PyTypeObject deque_type = {
16451655
PyVarObject_HEAD_INIT(NULL, 0)
@@ -2022,7 +2032,8 @@ new_defdict(defdictobject *dd, PyObject *arg)
20222032
dd->default_factory ? dd->default_factory : Py_None, arg, NULL);
20232033
}
20242034

2025-
PyDoc_STRVAR(defdict_copy_doc, "D.copy() -> a shallow copy of D.");
2035+
PyDoc_STRVAR(defdict_copy_doc, "copy() -> collections.deque\n\n"
2036+
"A shallow copy of the deque.");
20262037

20272038
static PyObject *
20282039
defdict_copy(defdictobject *dd, PyObject *Py_UNUSED(ignored))

0 commit comments

Comments
 (0)