diff --git a/Lib/test/pickletester.py b/Lib/test/pickletester.py index 6ef4c8989f5..7758ff8ef9e 100644 --- a/Lib/test/pickletester.py +++ b/Lib/test/pickletester.py @@ -3404,7 +3404,10 @@ class AbstractPicklerUnpicklerObjectTests(unittest.TestCase): 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 c3385ad3b9e..2b9d3f6f73d 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;