[pypy-commit] pypy py3.6: test, fix ImportError.__reduce__ for new attributes

mattip pypy.commits at gmail.com
Thu Sep 5 15:46:09 EDT 2019


Author: Matti Picus <matti.picus at gmail.com>
Branch: py3.6
Changeset: r97381:a6c3470d8f75
Date: 2019-09-05 17:47 +0200
http://bitbucket.org/pypy/pypy/changeset/a6c3470d8f75/

Log:	test, fix ImportError.__reduce__ for new attributes

diff --git a/pypy/module/exceptions/interp_exceptions.py b/pypy/module/exceptions/interp_exceptions.py
--- a/pypy/module/exceptions/interp_exceptions.py
+++ b/pypy/module/exceptions/interp_exceptions.py
@@ -342,6 +342,14 @@
             self.w_msg = space.w_None
         W_Exception.descr_init(self, space, args_w)
 
+    def descr_reduce(self, space):
+        w_dct = space.newdict()
+        space.setitem(w_dct, space.newtext('name'), self.w_name)
+        space.setitem(w_dct, space.newtext('path'), self.w_path)
+        return space.newtuple([space.w_ImportError,
+                    space.newtuple([self.w_msg]),
+                    w_dct,
+                ])
 
 W_ImportError.typedef = TypeDef(
     'ImportError',
@@ -353,6 +361,7 @@
     name = readwrite_attrproperty_w('w_name', W_ImportError),
     path = readwrite_attrproperty_w('w_path', W_ImportError),
     msg = readwrite_attrproperty_w('w_msg', W_ImportError),
+    __reduce__ = interp2app(W_ImportError.descr_reduce),
 )
 
 
diff --git a/pypy/module/exceptions/test/test_exc.py b/pypy/module/exceptions/test/test_exc.py
--- a/pypy/module/exceptions/test/test_exc.py
+++ b/pypy/module/exceptions/test/test_exc.py
@@ -303,6 +303,14 @@
         assert ImportError("message", "foo").msg is None
         assert ImportError("message", "foo").args == ("message", "foo")
 
+    def test_importerror_reduce(self):
+        d = {'name': 'a',
+             'path': 'b',
+            } 
+        s = ImportError('c', **d).__reduce__()
+        e = s[0](*s[1], **s[2])
+        for k, v in d.items():
+            assert getattr(e, k) == v
 
     def test_modulenotfounderror(self):
         assert ModuleNotFoundError("message").name is None


More information about the pypy-commit mailing list