[pypy-commit] pypy py3.6: (cfbolz, ambv) [pickle, object] __getnewargs_ex__() is now used in protocols 2 and 3

ambv pypy.commits at gmail.com
Mon Feb 4 10:37:55 EST 2019


Author: Łukasz Langa <lukasz at langa.pl>
Branch: py3.6
Changeset: r95794:bae9ac47e0a5
Date: 2019-02-04 16:37 +0100
http://bitbucket.org/pypy/pypy/changeset/bae9ac47e0a5/

Log:	(cfbolz,ambv) [pickle,object] __getnewargs_ex__() is now used in
	protocols 2 and 3

	This is a change in Python 3.6.

diff --git a/pypy/objspace/std/objectobject.py b/pypy/objspace/std/objectobject.py
--- a/pypy/objspace/std/objectobject.py
+++ b/pypy/objspace/std/objectobject.py
@@ -59,13 +59,9 @@
     if not kwargs:
        newobj = copyreg.__newobj__
        args2 = (cls,) + args
-    elif proto >= 4:
+    else:
        newobj = copyreg.__newobj_ex__
        args2 = (cls, args, kwargs)
-    else:
-       raise ValueError("must use protocol 4 or greater to copy this "
-                        "object; since __getnewargs_ex__ returned "
-                        "keyword arguments.")
     state = _getstate(obj)
     listitems = iter(obj) if isinstance(obj, list) else None
     dictitems = iter(obj.items()) if isinstance(obj, dict) else None
diff --git a/pypy/objspace/std/test/test_obj.py b/pypy/objspace/std/test/test_obj.py
--- a/pypy/objspace/std/test/test_obj.py
+++ b/pypy/objspace/std/test/test_obj.py
@@ -70,10 +70,11 @@
             def __getnewargs_ex__(self):
                 return (self._name,), dict(value=int(self))
         import copyreg
-        assert NamedInt("Name", value=42).__reduce__(4) == (
-            copyreg.__newobj_ex__,
-            (NamedInt, ('Name',), dict(value=42)),
-            dict(_name='Name'), None, None)
+        for protocol in [2, 3, 4]:
+            assert NamedInt("Name", value=42).__reduce__(protocol) == (
+                copyreg.__newobj_ex__,
+                (NamedInt, ('Name',), dict(value=42)),
+                dict(_name='Name'), None, None)
 
     def test_reduce_ex_does_getattr(self):
         seen = []


More information about the pypy-commit mailing list