diff --git a/Misc/NEWS.d/next/Library/2023-11-08-18-47-33.gh-issue-111835.1LuxPJ.rst b/Misc/NEWS.d/next/Library/2023-11-08-18-47-33.gh-issue-111835.1LuxPJ.rst new file mode 100644 index 00000000000000..68a1cd19e3acfa --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-11-08-18-47-33.gh-issue-111835.1LuxPJ.rst @@ -0,0 +1 @@ +The :class:`mmap.mmap` class now has an :meth:`~mmap.mmap.seekable` method that can be used where a file-like object with a seekable method is required. (Contributed by Sylvie Liberman in :gh:`111865`.) diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c index d11200a4042551..f6300e6890af12 100644 --- a/Modules/mmapmodule.c +++ b/Modules/mmapmodule.c @@ -737,6 +737,14 @@ mmap_seek_method(mmap_object *self, PyObject *args) return NULL; } + +static PyObject * +mmap_seekable_method(mmap_object *self, PyObject *unused) +{ + Py_RETURN_TRUE; +} + + static PyObject * mmap_move_method(mmap_object *self, PyObject *args) { @@ -905,6 +913,7 @@ static struct PyMethodDef mmap_object_methods[] = { {"readline", (PyCFunction) mmap_read_line_method, METH_NOARGS}, {"resize", (PyCFunction) mmap_resize_method, METH_VARARGS}, {"seek", (PyCFunction) mmap_seek_method, METH_VARARGS}, + {"seekable", (PyCFunction) mmap_seekable_method, METH_NOARGS}, {"size", (PyCFunction) mmap_size_method, METH_NOARGS}, {"tell", (PyCFunction) mmap_tell_method, METH_NOARGS}, {"write", (PyCFunction) mmap_write_method, METH_VARARGS},