[Python-checkins] bpo-39435: Make the first argument of pickle.loads() positional-only. (GH-19846)

Serhiy Storchaka webhook-mailer at python.org
Sat May 2 02:38:09 EDT 2020


https://github.com/python/cpython/commit/531d1e541284bfd7944f8c66a5e8c3c3234afaff
commit: 531d1e541284bfd7944f8c66a5e8c3c3234afaff
branch: master
author: Serhiy Storchaka <storchaka at gmail.com>
committer: GitHub <noreply at github.com>
date: 2020-05-02T09:38:01+03:00
summary:

bpo-39435: Make the first argument of pickle.loads() positional-only. (GH-19846)

It was positional-only de facto: documentation and two implementations
used three different name.

files:
A Misc/NEWS.d/next/Library/2020-05-01-23-24-25.bpo-39435.mgb6ib.rst
M Doc/library/pickle.rst
M Lib/pickle.py
M Modules/_pickle.c
M Modules/clinic/_pickle.c.h

diff --git a/Doc/library/pickle.rst b/Doc/library/pickle.rst
index d92e947a76403..b7c3452771948 100644
--- a/Doc/library/pickle.rst
+++ b/Doc/library/pickle.rst
@@ -252,7 +252,7 @@ process more convenient:
    .. versionchanged:: 3.8
       The *buffers* argument was added.
 
-.. function:: loads(data, \*, fix_imports=True, encoding="ASCII", errors="strict", buffers=None)
+.. function:: loads(data, /, \*, fix_imports=True, encoding="ASCII", errors="strict", buffers=None)
 
    Return the reconstituted object hierarchy of the pickled representation
    *data* of an object. *data* must be a :term:`bytes-like object`.
diff --git a/Lib/pickle.py b/Lib/pickle.py
index 1fc8b0d26c6c4..cbac5f168b45e 100644
--- a/Lib/pickle.py
+++ b/Lib/pickle.py
@@ -13,7 +13,7 @@
     dump(object, file)
     dumps(object) -> string
     load(file) -> object
-    loads(string) -> object
+    loads(bytes) -> object
 
 Misc variables:
 
@@ -1761,7 +1761,7 @@ def _load(file, *, fix_imports=True, encoding="ASCII", errors="strict",
     return _Unpickler(file, fix_imports=fix_imports, buffers=buffers,
                      encoding=encoding, errors=errors).load()
 
-def _loads(s, *, fix_imports=True, encoding="ASCII", errors="strict",
+def _loads(s, /, *, fix_imports=True, encoding="ASCII", errors="strict",
            buffers=None):
     if isinstance(s, str):
         raise TypeError("Can't load pickle from unicode string")
diff --git a/Misc/NEWS.d/next/Library/2020-05-01-23-24-25.bpo-39435.mgb6ib.rst b/Misc/NEWS.d/next/Library/2020-05-01-23-24-25.bpo-39435.mgb6ib.rst
new file mode 100644
index 0000000000000..2a516a53ed9e2
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2020-05-01-23-24-25.bpo-39435.mgb6ib.rst
@@ -0,0 +1 @@
+The first argument of :func:`pickle.loads` is now positional-only.
diff --git a/Modules/_pickle.c b/Modules/_pickle.c
index d07fa53a1235e..5539e64025a39 100644
--- a/Modules/_pickle.c
+++ b/Modules/_pickle.c
@@ -7873,6 +7873,7 @@ _pickle_load_impl(PyObject *module, PyObject *file, int fix_imports,
 _pickle.loads
 
   data: object
+  /
   *
   fix_imports: bool = True
   encoding: str = 'ASCII'
@@ -7899,7 +7900,7 @@ static PyObject *
 _pickle_loads_impl(PyObject *module, PyObject *data, int fix_imports,
                    const char *encoding, const char *errors,
                    PyObject *buffers)
-/*[clinic end generated code: output=82ac1e6b588e6d02 input=9c2ab6a0960185ea]*/
+/*[clinic end generated code: output=82ac1e6b588e6d02 input=b3615540d0535087]*/
 {
     PyObject *result;
     UnpicklerObject *unpickler = _Unpickler_New();
diff --git a/Modules/clinic/_pickle.c.h b/Modules/clinic/_pickle.c.h
index 0457a433e79fb..136524b6a7134 100644
--- a/Modules/clinic/_pickle.c.h
+++ b/Modules/clinic/_pickle.c.h
@@ -735,7 +735,7 @@ _pickle_load(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject
 }
 
 PyDoc_STRVAR(_pickle_loads__doc__,
-"loads($module, /, data, *, fix_imports=True, encoding=\'ASCII\',\n"
+"loads($module, data, /, *, fix_imports=True, encoding=\'ASCII\',\n"
 "      errors=\'strict\', buffers=())\n"
 "--\n"
 "\n"
@@ -766,7 +766,7 @@ static PyObject *
 _pickle_loads(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
 {
     PyObject *return_value = NULL;
-    static const char * const _keywords[] = {"data", "fix_imports", "encoding", "errors", "buffers", NULL};
+    static const char * const _keywords[] = {"", "fix_imports", "encoding", "errors", "buffers", NULL};
     static _PyArg_Parser _parser = {NULL, _keywords, "loads", 0};
     PyObject *argsbuf[5];
     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
@@ -836,4 +836,4 @@ _pickle_loads(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObjec
 exit:
     return return_value;
 }
-/*[clinic end generated code: output=e2506823be1960c5 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=324aad69644beda2 input=a9049054013a1b77]*/



More information about the Python-checkins mailing list