From 2b54cce96cf7a35d0e647cd7b0c5b2f6c725960a Mon Sep 17 00:00:00 2001 From: Zackery Spytz Date: Mon, 30 Mar 2020 16:09:20 -0600 Subject: [PATCH 1/2] bpo-39734: Deprecate the readinto() fallback path in _pickle.c --- Lib/test/pickletester.py | 5 ++++- Modules/_pickle.c | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Lib/test/pickletester.py b/Lib/test/pickletester.py index 6ef4c8989f55bf..7758ff8ef9e4af 100644 --- a/Lib/test/pickletester.py +++ b/Lib/test/pickletester.py @@ -3404,7 +3404,10 @@ def test_multiple_unpicklings_unseekable(self): def test_multiple_unpicklings_minimal(self): # File-like object that doesn't support peek() and readinto() # (bpo-39681) - self._check_multiple_unpicklings(MinimalIO, seekable=False) + import warnings + with warnings.catch_warnings(): + warnings.simplefilter("ignore", DeprecationWarning) + self._check_multiple_unpicklings(MinimalIO, seekable=False) def test_unpickling_buffering_readline(self): # Issue #12687: the unpickler's buffering logic could fail with diff --git a/Modules/_pickle.c b/Modules/_pickle.c index c3385ad3b9ec6a..2b9d3f6f73d4e8 100644 --- a/Modules/_pickle.c +++ b/Modules/_pickle.c @@ -1384,6 +1384,11 @@ _Unpickler_ReadInto(UnpicklerObject *self, char *buf, Py_ssize_t n) if (!self->readinto) { /* readinto() not supported on file-like object, fall back to read() * and copy into destination buffer (bpo-39681) */ + if (PyErr_WarnEx(PyExc_DeprecationWarning, + "file-like object should provide readinto()", + 1) < 0) { + return -1; + } PyObject* len = PyLong_FromSsize_t(n); if (len == NULL) { return -1; From ea5012d761fd45ba41599f6c242c80eb988cba34 Mon Sep 17 00:00:00 2001 From: Irit Katriel <1055913+iritkatriel@users.noreply.github.com> Date: Wed, 9 Nov 2022 14:06:19 +0000 Subject: [PATCH 2/2] used assertWarns in the test --- Lib/test/pickletester.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Lib/test/pickletester.py b/Lib/test/pickletester.py index de580bae431c3e..98559b92a8fc7b 100644 --- a/Lib/test/pickletester.py +++ b/Lib/test/pickletester.py @@ -3707,9 +3707,7 @@ def test_multiple_unpicklings_unseekable(self): def test_multiple_unpicklings_minimal(self): # File-like object that doesn't support peek() and readinto() # (bpo-39681) - import warnings - with warnings.catch_warnings(): - warnings.simplefilter("ignore", DeprecationWarning) + with self.assertWarns(DeprecationWarning): self._check_multiple_unpicklings(MinimalIO, seekable=False) def test_unpickling_buffering_readline(self):