From 4bac18ab63d06eae9b4276b56ee768f22b892673 Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Wed, 8 Nov 2023 23:32:21 +0900 Subject: [PATCH 01/15] gh-111835: Add seekable method to mmap.mmap --- Lib/test/test_mmap.py | 1 + ...-11-08-23-32-03.gh-issue-111835.ufFiuW.rst | 3 +++ Modules/mmapmodule.c | 19 +++++++++++++------ 3 files changed, 17 insertions(+), 6 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2023-11-08-23-32-03.gh-issue-111835.ufFiuW.rst diff --git a/Lib/test/test_mmap.py b/Lib/test/test_mmap.py index dfcf3039422af5e..3bfdb3919c77ee4 100644 --- a/Lib/test/test_mmap.py +++ b/Lib/test/test_mmap.py @@ -93,6 +93,7 @@ def test_basic(self): self.assertEqual(end, PAGESIZE + 6) # test seeking around (try to overflow the seek implementation) + self.assertTrue(m.seekable()) m.seek(0,0) self.assertEqual(m.tell(), 0) m.seek(42,1) diff --git a/Misc/NEWS.d/next/Library/2023-11-08-23-32-03.gh-issue-111835.ufFiuW.rst b/Misc/NEWS.d/next/Library/2023-11-08-23-32-03.gh-issue-111835.ufFiuW.rst new file mode 100644 index 000000000000000..ef0b3850a515d9a --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-11-08-23-32-03.gh-issue-111835.ufFiuW.rst @@ -0,0 +1,3 @@ +The :class:`mmap.mmap` class now has an :meth:`~mmap.mmap.seekable` method +that can be used where it requires a file-like object with seekable. Patch +by Donghee Na. diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c index d11200a40425518..ffd1194d5e33363 100644 --- a/Modules/mmapmodule.c +++ b/Modules/mmapmodule.c @@ -171,7 +171,7 @@ mmap_object_dealloc(mmap_object *m_obj) } static PyObject * -mmap_close_method(mmap_object *self, PyObject *unused) +mmap_close_method(mmap_object *self, PyObject *Py_UNUSED(ignored)) { if (self->exports > 0) { PyErr_SetString(PyExc_BufferError, "cannot close "\ @@ -260,7 +260,7 @@ do { \ static PyObject * mmap_read_byte_method(mmap_object *self, - PyObject *unused) + PyObject *Py_UNUSED(ignored)) { CHECK_VALID(NULL); if (self->pos >= self->size) { @@ -272,7 +272,7 @@ mmap_read_byte_method(mmap_object *self, static PyObject * mmap_read_line_method(mmap_object *self, - PyObject *unused) + PyObject *Py_UNUSED(ignored)) { Py_ssize_t remaining; char *start, *eol; @@ -460,7 +460,7 @@ mmap_write_byte_method(mmap_object *self, static PyObject * mmap_size_method(mmap_object *self, - PyObject *unused) + PyObject *Py_UNUSED(ignored)) { CHECK_VALID(NULL); @@ -657,7 +657,7 @@ mmap_resize_method(mmap_object *self, } static PyObject * -mmap_tell_method(mmap_object *self, PyObject *unused) +mmap_tell_method(mmap_object *self, PyObject *Py_UNUSED(ignored)) { CHECK_VALID(NULL); return PyLong_FromSize_t(self->pos); @@ -737,6 +737,12 @@ mmap_seek_method(mmap_object *self, PyObject *args) return NULL; } +static PyObject * +mmap_seekable_method(mmap_object *self, PyObject *Py_UNUSED(ignored)) +{ + Py_RETURN_TRUE; +} + static PyObject * mmap_move_method(mmap_object *self, PyObject *args) { @@ -835,7 +841,7 @@ mmap__repr__method(PyObject *self) #ifdef MS_WINDOWS static PyObject * -mmap__sizeof__method(mmap_object *self, void *unused) +mmap__sizeof__method(mmap_object *self, void *Py_UNUSED(ignored)) { size_t res = _PyObject_SIZE(Py_TYPE(self)); if (self->tagname) { @@ -905,6 +911,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}, From 7e69d94451db6cdbb6550b629671654f895fdda6 Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Wed, 8 Nov 2023 23:35:37 +0900 Subject: [PATCH 02/15] Add whats news --- Doc/whatsnew/3.13.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Doc/whatsnew/3.13.rst b/Doc/whatsnew/3.13.rst index cca282727ab951c..6631b099d552194 100644 --- a/Doc/whatsnew/3.13.rst +++ b/Doc/whatsnew/3.13.rst @@ -185,6 +185,14 @@ and only logged in :ref:`Python Development Mode ` or on :ref:`Python built on debug mode `. (Contributed by Victor Stinner in :gh:`62948`.) + +mmap +---- + +* The :class:`mmap.mmap` class now has an :meth:`~mmap.mmap.seekable` method + that can be used where it requires a file-like object with seekable. + (Contributed by Donghee Na in :gh:`111835`.) + ipaddress --------- From ebc837d3cad6a4741d631afc4598c42d9f79ca72 Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Wed, 8 Nov 2023 23:39:26 +0900 Subject: [PATCH 03/15] Update mmap.rst --- Doc/library/mmap.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Doc/library/mmap.rst b/Doc/library/mmap.rst index 4ca7a64451d4c72..6b4b4111677c312 100644 --- a/Doc/library/mmap.rst +++ b/Doc/library/mmap.rst @@ -285,6 +285,11 @@ To map anonymous memory, -1 should be passed as the fileno along with the length values are ``os.SEEK_CUR`` or ``1`` (seek relative to the current position) and ``os.SEEK_END`` or ``2`` (seek relative to the file's end). + .. method:: seekable() + + Return whether the file supports seeking. + + .. versionadded:: 3.13 .. method:: size() From d699f9833c487505742973eafea08b71d613ec7c Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Wed, 8 Nov 2023 23:32:21 +0900 Subject: [PATCH 04/15] gh-111835: Add seekable method to mmap.mmap --- Lib/test/test_mmap.py | 1 + ...-11-08-23-32-03.gh-issue-111835.ufFiuW.rst | 3 +++ Modules/mmapmodule.c | 19 +++++++++++++------ 3 files changed, 17 insertions(+), 6 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2023-11-08-23-32-03.gh-issue-111835.ufFiuW.rst diff --git a/Lib/test/test_mmap.py b/Lib/test/test_mmap.py index dfcf3039422af5e..3bfdb3919c77ee4 100644 --- a/Lib/test/test_mmap.py +++ b/Lib/test/test_mmap.py @@ -93,6 +93,7 @@ def test_basic(self): self.assertEqual(end, PAGESIZE + 6) # test seeking around (try to overflow the seek implementation) + self.assertTrue(m.seekable()) m.seek(0,0) self.assertEqual(m.tell(), 0) m.seek(42,1) diff --git a/Misc/NEWS.d/next/Library/2023-11-08-23-32-03.gh-issue-111835.ufFiuW.rst b/Misc/NEWS.d/next/Library/2023-11-08-23-32-03.gh-issue-111835.ufFiuW.rst new file mode 100644 index 000000000000000..ef0b3850a515d9a --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-11-08-23-32-03.gh-issue-111835.ufFiuW.rst @@ -0,0 +1,3 @@ +The :class:`mmap.mmap` class now has an :meth:`~mmap.mmap.seekable` method +that can be used where it requires a file-like object with seekable. Patch +by Donghee Na. diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c index d11200a40425518..ffd1194d5e33363 100644 --- a/Modules/mmapmodule.c +++ b/Modules/mmapmodule.c @@ -171,7 +171,7 @@ mmap_object_dealloc(mmap_object *m_obj) } static PyObject * -mmap_close_method(mmap_object *self, PyObject *unused) +mmap_close_method(mmap_object *self, PyObject *Py_UNUSED(ignored)) { if (self->exports > 0) { PyErr_SetString(PyExc_BufferError, "cannot close "\ @@ -260,7 +260,7 @@ do { \ static PyObject * mmap_read_byte_method(mmap_object *self, - PyObject *unused) + PyObject *Py_UNUSED(ignored)) { CHECK_VALID(NULL); if (self->pos >= self->size) { @@ -272,7 +272,7 @@ mmap_read_byte_method(mmap_object *self, static PyObject * mmap_read_line_method(mmap_object *self, - PyObject *unused) + PyObject *Py_UNUSED(ignored)) { Py_ssize_t remaining; char *start, *eol; @@ -460,7 +460,7 @@ mmap_write_byte_method(mmap_object *self, static PyObject * mmap_size_method(mmap_object *self, - PyObject *unused) + PyObject *Py_UNUSED(ignored)) { CHECK_VALID(NULL); @@ -657,7 +657,7 @@ mmap_resize_method(mmap_object *self, } static PyObject * -mmap_tell_method(mmap_object *self, PyObject *unused) +mmap_tell_method(mmap_object *self, PyObject *Py_UNUSED(ignored)) { CHECK_VALID(NULL); return PyLong_FromSize_t(self->pos); @@ -737,6 +737,12 @@ mmap_seek_method(mmap_object *self, PyObject *args) return NULL; } +static PyObject * +mmap_seekable_method(mmap_object *self, PyObject *Py_UNUSED(ignored)) +{ + Py_RETURN_TRUE; +} + static PyObject * mmap_move_method(mmap_object *self, PyObject *args) { @@ -835,7 +841,7 @@ mmap__repr__method(PyObject *self) #ifdef MS_WINDOWS static PyObject * -mmap__sizeof__method(mmap_object *self, void *unused) +mmap__sizeof__method(mmap_object *self, void *Py_UNUSED(ignored)) { size_t res = _PyObject_SIZE(Py_TYPE(self)); if (self->tagname) { @@ -905,6 +911,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}, From c56a81002b777b0bd1135cd4c9eea265c9cedff3 Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Wed, 8 Nov 2023 23:35:37 +0900 Subject: [PATCH 05/15] Add whats news --- Doc/whatsnew/3.13.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Doc/whatsnew/3.13.rst b/Doc/whatsnew/3.13.rst index 291e276dc67ce09..f788f53d00d5367 100644 --- a/Doc/whatsnew/3.13.rst +++ b/Doc/whatsnew/3.13.rst @@ -185,6 +185,14 @@ and only logged in :ref:`Python Development Mode ` or on :ref:`Python built on debug mode `. (Contributed by Victor Stinner in :gh:`62948`.) + +mmap +---- + +* The :class:`mmap.mmap` class now has an :meth:`~mmap.mmap.seekable` method + that can be used where it requires a file-like object with seekable. + (Contributed by Donghee Na in :gh:`111835`.) + ipaddress --------- From 9748be99c458323caf49e096f631b410658c92c3 Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Wed, 8 Nov 2023 23:39:26 +0900 Subject: [PATCH 06/15] Update mmap.rst --- Doc/library/mmap.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Doc/library/mmap.rst b/Doc/library/mmap.rst index 4ca7a64451d4c72..6b4b4111677c312 100644 --- a/Doc/library/mmap.rst +++ b/Doc/library/mmap.rst @@ -285,6 +285,11 @@ To map anonymous memory, -1 should be passed as the fileno along with the length values are ``os.SEEK_CUR`` or ``1`` (seek relative to the current position) and ``os.SEEK_END`` or ``2`` (seek relative to the file's end). + .. method:: seekable() + + Return whether the file supports seeking. + + .. versionadded:: 3.13 .. method:: size() From 9021e4e1fb6893b0cf55fca7ff09d935b6c86191 Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Thu, 9 Nov 2023 00:21:15 +0900 Subject: [PATCH 07/15] Address Victor's review --- Doc/library/mmap.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/mmap.rst b/Doc/library/mmap.rst index 6b4b4111677c312..b3a8bdcbcfec694 100644 --- a/Doc/library/mmap.rst +++ b/Doc/library/mmap.rst @@ -287,7 +287,7 @@ To map anonymous memory, -1 should be passed as the fileno along with the length .. method:: seekable() - Return whether the file supports seeking. + Return whether the file supports seeking, and the return value is always ``True``. .. versionadded:: 3.13 From fa0182339f661783622b71a596bad733fee8d918 Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Thu, 9 Nov 2023 07:11:50 +0900 Subject: [PATCH 08/15] Update mmap.seek() to return the current position --- Lib/test/test_mmap.py | 6 +++--- Modules/mmapmodule.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Lib/test/test_mmap.py b/Lib/test/test_mmap.py index 3bfdb3919c77ee4..f20115714d33504 100644 --- a/Lib/test/test_mmap.py +++ b/Lib/test/test_mmap.py @@ -94,11 +94,11 @@ def test_basic(self): # test seeking around (try to overflow the seek implementation) self.assertTrue(m.seekable()) - m.seek(0,0) + self.assertEqual(m.seek(0,0), 0) self.assertEqual(m.tell(), 0) - m.seek(42,1) + self.assertEqual(m.seek(42,1), 42) self.assertEqual(m.tell(), 42) - m.seek(0,2) + self.assertEqual(m.seek(0,2), len(m)) self.assertEqual(m.tell(), len(m)) # Try to seek to negative position... diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c index ffd1194d5e33363..f8f0d2468a468a3 100644 --- a/Modules/mmapmodule.c +++ b/Modules/mmapmodule.c @@ -729,7 +729,7 @@ mmap_seek_method(mmap_object *self, PyObject *args) if (where > self->size || where < 0) goto onoutofrange; self->pos = where; - Py_RETURN_NONE; + return PyLong_FromLong(self->pos); } onoutofrange: From db9387e6ebb44967fb0d221727b6a1f01e24d564 Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Thu, 9 Nov 2023 07:16:41 +0900 Subject: [PATCH 09/15] Update documentation --- Doc/library/mmap.rst | 3 +++ Doc/whatsnew/3.13.rst | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Doc/library/mmap.rst b/Doc/library/mmap.rst index b3a8bdcbcfec694..f5659035528d6c1 100644 --- a/Doc/library/mmap.rst +++ b/Doc/library/mmap.rst @@ -285,6 +285,9 @@ To map anonymous memory, -1 should be passed as the fileno along with the length values are ``os.SEEK_CUR`` or ``1`` (seek relative to the current position) and ``os.SEEK_END`` or ``2`` (seek relative to the file's end). + .. versionchanged:: 3.13 + Return the current position instead of ``None``. + .. method:: seekable() Return whether the file supports seeking, and the return value is always ``True``. diff --git a/Doc/whatsnew/3.13.rst b/Doc/whatsnew/3.13.rst index f788f53d00d5367..fd0a982a870cfec 100644 --- a/Doc/whatsnew/3.13.rst +++ b/Doc/whatsnew/3.13.rst @@ -190,7 +190,8 @@ mmap ---- * The :class:`mmap.mmap` class now has an :meth:`~mmap.mmap.seekable` method - that can be used where it requires a file-like object with seekable. + that can be used where it requires a file-like object with seekable and + the :meth:`~mmap.mmap.seek` method return the current position. (Contributed by Donghee Na in :gh:`111835`.) ipaddress From 08e99667f67793127c5a33e1b71c164a23b0e471 Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Thu, 9 Nov 2023 07:20:07 +0900 Subject: [PATCH 10/15] Remove white space --- Doc/whatsnew/3.13.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/whatsnew/3.13.rst b/Doc/whatsnew/3.13.rst index fd0a982a870cfec..c420ddae5a88d6f 100644 --- a/Doc/whatsnew/3.13.rst +++ b/Doc/whatsnew/3.13.rst @@ -190,7 +190,7 @@ mmap ---- * The :class:`mmap.mmap` class now has an :meth:`~mmap.mmap.seekable` method - that can be used where it requires a file-like object with seekable and + that can be used where it requires a file-like object with seekable and the :meth:`~mmap.mmap.seek` method return the current position. (Contributed by Donghee Na in :gh:`111835`.) From d576c8c96233989e2a62a7132eccb72415ada025 Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Thu, 9 Nov 2023 07:20:56 +0900 Subject: [PATCH 11/15] Add credit --- Doc/whatsnew/3.13.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/whatsnew/3.13.rst b/Doc/whatsnew/3.13.rst index c420ddae5a88d6f..6fa4dc578dfe766 100644 --- a/Doc/whatsnew/3.13.rst +++ b/Doc/whatsnew/3.13.rst @@ -166,7 +166,7 @@ dbm * Add :meth:`dbm.gnu.gdbm.clear` and :meth:`dbm.ndbm.ndbm.clear` methods that remove all items from the database. - (Contributed by Donghee Na in :gh:`107122`.) + (Contributed by Donghee Na and Sylvie Liberman in :gh:`107122`.) doctest ------- From 0ed19e4dd6b3551e9948931909aa3055955b1a96 Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Thu, 9 Nov 2023 07:21:36 +0900 Subject: [PATCH 12/15] Update credit --- Doc/whatsnew/3.13.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/whatsnew/3.13.rst b/Doc/whatsnew/3.13.rst index 6fa4dc578dfe766..033fc2f73e64e0d 100644 --- a/Doc/whatsnew/3.13.rst +++ b/Doc/whatsnew/3.13.rst @@ -166,7 +166,7 @@ dbm * Add :meth:`dbm.gnu.gdbm.clear` and :meth:`dbm.ndbm.ndbm.clear` methods that remove all items from the database. - (Contributed by Donghee Na and Sylvie Liberman in :gh:`107122`.) + (Contributed by Donghee Na in :gh:`107122`.) doctest ------- @@ -192,7 +192,7 @@ mmap * The :class:`mmap.mmap` class now has an :meth:`~mmap.mmap.seekable` method that can be used where it requires a file-like object with seekable and the :meth:`~mmap.mmap.seek` method return the current position. - (Contributed by Donghee Na in :gh:`111835`.) + (Contributed by Donghee Na and Sylvie Liberman in :gh:`111835`.) ipaddress --------- From 55f47cb51d41a385b5ca5199da3890e631c5a553 Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Thu, 9 Nov 2023 07:30:03 +0900 Subject: [PATCH 13/15] Use PyLong_FromSsize_t --- Modules/mmapmodule.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c index f8f0d2468a468a3..66ed0b8efb775c1 100644 --- a/Modules/mmapmodule.c +++ b/Modules/mmapmodule.c @@ -729,7 +729,7 @@ mmap_seek_method(mmap_object *self, PyObject *args) if (where > self->size || where < 0) goto onoutofrange; self->pos = where; - return PyLong_FromLong(self->pos); + return PyLong_FromSsize_t(self->pos); } onoutofrange: From ff11b753e4c5f75909f776911cde267f82075b58 Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Thu, 9 Nov 2023 16:52:03 +0900 Subject: [PATCH 14/15] Address code review --- Doc/library/mmap.rst | 2 +- Doc/whatsnew/3.13.rst | 11 +++++------ Lib/test/test_mmap.py | 10 +++++----- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/Doc/library/mmap.rst b/Doc/library/mmap.rst index f5659035528d6c1..62dc773b3885658 100644 --- a/Doc/library/mmap.rst +++ b/Doc/library/mmap.rst @@ -286,7 +286,7 @@ To map anonymous memory, -1 should be passed as the fileno along with the length position) and ``os.SEEK_END`` or ``2`` (seek relative to the file's end). .. versionchanged:: 3.13 - Return the current position instead of ``None``. + Return the current position instead of ``None``. .. method:: seekable() diff --git a/Doc/whatsnew/3.13.rst b/Doc/whatsnew/3.13.rst index 033fc2f73e64e0d..6b79dc68ada803f 100644 --- a/Doc/whatsnew/3.13.rst +++ b/Doc/whatsnew/3.13.rst @@ -185,6 +185,11 @@ and only logged in :ref:`Python Development Mode ` or on :ref:`Python built on debug mode `. (Contributed by Victor Stinner in :gh:`62948`.) +ipaddress +--------- + +* Add the :attr:`ipaddress.IPv4Address.ipv6_mapped` property, which returns the IPv4-mapped IPv6 address. + (Contributed by Charles Machalow in :gh:`109466`.) mmap ---- @@ -194,12 +199,6 @@ mmap the :meth:`~mmap.mmap.seek` method return the current position. (Contributed by Donghee Na and Sylvie Liberman in :gh:`111835`.) -ipaddress ---------- - -* Add the :attr:`ipaddress.IPv4Address.ipv6_mapped` property, which returns the IPv4-mapped IPv6 address. - (Contributed by Charles Machalow in :gh:`109466`.) - opcode ------ diff --git a/Lib/test/test_mmap.py b/Lib/test/test_mmap.py index f20115714d33504..866ede5b83dff08 100644 --- a/Lib/test/test_mmap.py +++ b/Lib/test/test_mmap.py @@ -94,11 +94,11 @@ def test_basic(self): # test seeking around (try to overflow the seek implementation) self.assertTrue(m.seekable()) - self.assertEqual(m.seek(0,0), 0) + self.assertEqual(m.seek(0, 0), 0) self.assertEqual(m.tell(), 0) - self.assertEqual(m.seek(42,1), 42) + self.assertEqual(m.seek(42, 1), 42) self.assertEqual(m.tell(), 42) - self.assertEqual(m.seek(0,2), len(m)) + self.assertEqual(m.seek(0, 2), len(m)) self.assertEqual(m.tell(), len(m)) # Try to seek to negative position... @@ -163,7 +163,7 @@ def test_access_parameter(self): # Ensuring that readonly mmap can't be write() to try: - m.seek(0,0) + m.seek(0, 0) m.write(b'abc') except TypeError: pass @@ -172,7 +172,7 @@ def test_access_parameter(self): # Ensuring that readonly mmap can't be write_byte() to try: - m.seek(0,0) + m.seek(0, 0) m.write_byte(b'd') except TypeError: pass From 0c4245b87bacb6288c50e3c64b528008bfb0a4cf Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Thu, 9 Nov 2023 17:49:14 +0900 Subject: [PATCH 15/15] Address code review --- Doc/library/mmap.rst | 2 +- Doc/whatsnew/3.13.rst | 2 +- .../Library/2023-11-08-23-32-03.gh-issue-111835.ufFiuW.rst | 5 +++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Doc/library/mmap.rst b/Doc/library/mmap.rst index 62dc773b3885658..3fa69e717329e44 100644 --- a/Doc/library/mmap.rst +++ b/Doc/library/mmap.rst @@ -286,7 +286,7 @@ To map anonymous memory, -1 should be passed as the fileno along with the length position) and ``os.SEEK_END`` or ``2`` (seek relative to the file's end). .. versionchanged:: 3.13 - Return the current position instead of ``None``. + Return the new absolute position instead of ``None``. .. method:: seekable() diff --git a/Doc/whatsnew/3.13.rst b/Doc/whatsnew/3.13.rst index 6b79dc68ada803f..32ed44dc860062c 100644 --- a/Doc/whatsnew/3.13.rst +++ b/Doc/whatsnew/3.13.rst @@ -196,7 +196,7 @@ mmap * The :class:`mmap.mmap` class now has an :meth:`~mmap.mmap.seekable` method that can be used where it requires a file-like object with seekable and - the :meth:`~mmap.mmap.seek` method return the current position. + the :meth:`~mmap.mmap.seek` method return the new absolute position. (Contributed by Donghee Na and Sylvie Liberman in :gh:`111835`.) opcode diff --git a/Misc/NEWS.d/next/Library/2023-11-08-23-32-03.gh-issue-111835.ufFiuW.rst b/Misc/NEWS.d/next/Library/2023-11-08-23-32-03.gh-issue-111835.ufFiuW.rst index ef0b3850a515d9a..5d06c22f477bab1 100644 --- a/Misc/NEWS.d/next/Library/2023-11-08-23-32-03.gh-issue-111835.ufFiuW.rst +++ b/Misc/NEWS.d/next/Library/2023-11-08-23-32-03.gh-issue-111835.ufFiuW.rst @@ -1,3 +1,4 @@ The :class:`mmap.mmap` class now has an :meth:`~mmap.mmap.seekable` method -that can be used where it requires a file-like object with seekable. Patch -by Donghee Na. +that can be used where it requires a file-like object with seekable and +the :meth:`~mmap.mmap.seek` method return the new absolute position. +Patch by Donghee Na.