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

Skip to content

Commit 397e5c9

Browse files
committed
Issue #15855: added docstrings for memoryview methods and data descriptors.
1 parent 94dd7cb commit 397e5c9

1 file changed

Lines changed: 43 additions & 11 deletions

File tree

Objects/memoryobject.c

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -402,14 +402,33 @@ memory_ndim_get(PyMemoryViewObject *self)
402402
return PyLong_FromLong(self->view.ndim);
403403
}
404404

405-
static PyGetSetDef memory_getsetlist[] ={
406-
{"format", (getter)memory_format_get, NULL, NULL},
407-
{"itemsize", (getter)memory_itemsize_get, NULL, NULL},
408-
{"shape", (getter)memory_shape_get, NULL, NULL},
409-
{"strides", (getter)memory_strides_get, NULL, NULL},
410-
{"suboffsets", (getter)memory_suboffsets_get, NULL, NULL},
411-
{"readonly", (getter)memory_readonly_get, NULL, NULL},
412-
{"ndim", (getter)memory_ndim_get, NULL, NULL},
405+
PyDoc_STRVAR(memory_format_doc,
406+
"A string containing the format (in struct module style)\n"
407+
" for each element in the view.");
408+
PyDoc_STRVAR(memory_itemsize_doc,
409+
"The size in bytes of each element of the memoryview.");
410+
PyDoc_STRVAR(memory_shape_doc,
411+
"A tuple of ndim integers giving the shape of the memory\n"
412+
" as an N-dimensional array.");
413+
PyDoc_STRVAR(memory_strides_doc,
414+
"A tuple of ndim integers giving the size in bytes to access\n"
415+
" each element for each dimension of the array.");
416+
PyDoc_STRVAR(memory_suboffsets_doc,
417+
"A tuple of integers used internally for PIL-style arrays.");
418+
PyDoc_STRVAR(memory_readonly_doc,
419+
"A bool indicating whether the memory is read only.");
420+
PyDoc_STRVAR(memory_ndim_doc,
421+
"An integer indicating how many dimensions of a multi-dimensional\n"
422+
" array the memory represents.");
423+
424+
static PyGetSetDef memory_getsetlist[] = {
425+
{"format", (getter)memory_format_get, NULL, memory_format_doc},
426+
{"itemsize", (getter)memory_itemsize_get, NULL, memory_itemsize_doc},
427+
{"shape", (getter)memory_shape_get, NULL, memory_shape_doc},
428+
{"strides", (getter)memory_strides_get, NULL, memory_strides_doc},
429+
{"suboffsets", (getter)memory_suboffsets_get, NULL, memory_suboffsets_doc},
430+
{"readonly", (getter)memory_readonly_get, NULL, memory_readonly_doc},
431+
{"ndim", (getter)memory_ndim_get, NULL, memory_ndim_doc},
413432
{NULL, NULL, NULL, NULL},
414433
};
415434

@@ -485,10 +504,23 @@ memory_exit(PyObject *self, PyObject *args)
485504
Py_RETURN_NONE;
486505
}
487506

507+
PyDoc_STRVAR(memory_release_doc,
508+
"M.release() -> None\n\
509+
\n\
510+
Release the underlying buffer exposed by the memoryview object.");
511+
PyDoc_STRVAR(memory_tobytes_doc,
512+
"M.tobytes() -> bytes\n\
513+
\n\
514+
Return the data in the buffer as a byte string.");
515+
PyDoc_STRVAR(memory_tolist_doc,
516+
"M.tolist() -> list\n\
517+
\n\
518+
Return the data in the buffer as a list of elements.");
519+
488520
static PyMethodDef memory_methods[] = {
489-
{"release", memory_exit, METH_NOARGS},
490-
{"tobytes", (PyCFunction)memory_tobytes, METH_NOARGS, NULL},
491-
{"tolist", (PyCFunction)memory_tolist, METH_NOARGS, NULL},
521+
{"release", memory_exit, METH_NOARGS, memory_release_doc},
522+
{"tobytes", (PyCFunction)memory_tobytes, METH_NOARGS, memory_tobytes_doc},
523+
{"tolist", (PyCFunction)memory_tolist, METH_NOARGS, memory_tolist_doc},
492524
{"__enter__", memory_enter, METH_NOARGS},
493525
{"__exit__", memory_exit, METH_VARARGS},
494526
{NULL, NULL} /* sentinel */

0 commit comments

Comments
 (0)