Skip to content

Commit f7dea0c

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 <ti.ludwig@web.de> Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
1 parent 592c344 commit f7dea0c

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
@@ -916,7 +916,9 @@ deque_rotate(dequeobject *deque, PyObject *const *args, Py_ssize_t nargs)
916916
}
917917

918918
PyDoc_STRVAR(rotate_doc,
919-
"Rotate the deque n steps to the right (default n=1). If n is negative, rotates left.");
919+
"rotate(n)\n\n"
920+
"Rotate the deque *n* steps to the right (default ``n=1``). "
921+
"If *n* is negative, rotates left.");
920922

921923
static PyObject *
922924
deque_reverse(dequeobject *deque, PyObject *unused)
@@ -957,7 +959,8 @@ deque_reverse(dequeobject *deque, PyObject *unused)
957959
}
958960

959961
PyDoc_STRVAR(reverse_doc,
960-
"D.reverse() -- reverse *IN PLACE*");
962+
"reverse()\n\n"
963+
"Reverse the elements of the deque *IN PLACE*.");
961964

962965
static PyObject *
963966
deque_count(dequeobject *deque, PyObject *v)
@@ -997,7 +1000,8 @@ deque_count(dequeobject *deque, PyObject *v)
9971000
}
9981001

9991002
PyDoc_STRVAR(count_doc,
1000-
"D.count(value) -> integer -- return number of occurrences of value");
1003+
"count(x) -> int\n\n"
1004+
"Count the number of deque elements equal to *x*.");
10011005

10021006
static int
10031007
deque_contains(dequeobject *deque, PyObject *v)
@@ -1106,8 +1110,10 @@ deque_index(dequeobject *deque, PyObject *const *args, Py_ssize_t nargs)
11061110
}
11071111

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

11121118
/* insert(), remove(), and delitem() are implemented in terms of
11131119
rotate() for simplicity and reasonable performance near the end
@@ -1152,10 +1158,13 @@ deque_insert(dequeobject *deque, PyObject *const *args, Py_ssize_t nargs)
11521158
}
11531159

11541160
PyDoc_STRVAR(insert_doc,
1155-
"D.insert(index, object) -- insert object before index");
1161+
"insert(i, x)\n\n"
1162+
"Insert *x* into the deque at position *i*.");
11561163

11571164
PyDoc_STRVAR(remove_doc,
1158-
"D.remove(value) -- remove first occurrence of value.");
1165+
"remove(x)\n\n"
1166+
"Remove the first occurrence of *x*."
1167+
"If not found, raises a ValueError.");
11591168

11601169
static int
11611170
valid_index(Py_ssize_t i, Py_ssize_t limit)
@@ -1534,7 +1543,8 @@ deque_sizeof(dequeobject *deque, void *unused)
15341543
}
15351544

15361545
PyDoc_STRVAR(sizeof_doc,
1537-
"D.__sizeof__() -- size of D in memory, in bytes");
1546+
"__sizeof__() -> int\n\n"
1547+
"Size of the deque in memory, in bytes.");
15381548

15391549
static PyObject *
15401550
deque_get_maxlen(dequeobject *deque, void *Py_UNUSED(ignored))
@@ -1569,7 +1579,8 @@ static PySequenceMethods deque_as_sequence = {
15691579
static PyObject *deque_iter(dequeobject *deque);
15701580
static PyObject *deque_reviter(dequeobject *deque, PyObject *Py_UNUSED(ignored));
15711581
PyDoc_STRVAR(reversed_doc,
1572-
"D.__reversed__() -- return a reverse iterator over the deque");
1582+
"__reversed__()\n\n"
1583+
"Return a reverse iterator over the deque.");
15731584

15741585
static PyMethodDef deque_methods[] = {
15751586
{"append", (PyCFunction)deque_append,
@@ -1614,9 +1625,8 @@ static PyMethodDef deque_methods[] = {
16141625
};
16151626

16161627
PyDoc_STRVAR(deque_doc,
1617-
"deque([iterable[, maxlen]]) --> deque object\n\
1618-
\n\
1619-
A list-like sequence optimized for data accesses near its endpoints.");
1628+
"deque([iterable[, maxlen]]) -> collections.deque\n\n"
1629+
"A list-like sequence optimized for data accesses near its endpoints.");
16201630

16211631
static PyTypeObject deque_type = {
16221632
PyVarObject_HEAD_INIT(NULL, 0)
@@ -1999,7 +2009,8 @@ new_defdict(defdictobject *dd, PyObject *arg)
19992009
dd->default_factory ? dd->default_factory : Py_None, arg, NULL);
20002010
}
20012011

2002-
PyDoc_STRVAR(defdict_copy_doc, "D.copy() -> a shallow copy of D.");
2012+
PyDoc_STRVAR(defdict_copy_doc, "copy() -> collections.deque\n\n"
2013+
"A shallow copy of the deque.");
20032014

20042015
static PyObject *
20052016
defdict_copy(defdictobject *dd, PyObject *Py_UNUSED(ignored))

0 commit comments

Comments
 (0)