]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-35312: Make lib2to3.pgen2.parse.ParseError round-trip pickle-able. (GH-10710)
authorAnthony Sottile <asottile@umich.edu>
Tue, 27 Nov 2018 18:39:49 +0000 (10:39 -0800)
committerSerhiy Storchaka <storchaka@gmail.com>
Tue, 27 Nov 2018 18:39:49 +0000 (20:39 +0200)
Lib/lib2to3/pgen2/parse.py
Lib/lib2to3/tests/test_parser.py
Misc/NEWS.d/next/Library/2018-11-25-20-05-33.bpo-35312.wbw0zO.rst [new file with mode: 0644]

index 6bebdbba7e52d6bb10c39104cef4ba21922b436e..cf3fcf7e99fd11d55fa5567801632f73629ba58c 100644 (file)
@@ -24,6 +24,9 @@ class ParseError(Exception):
         self.value = value
         self.context = context
 
+    def __reduce__(self):
+        return type(self), (self.msg, self.type, self.value, self.context)
+
 class Parser(object):
     """Parser engine.
 
index 829e5a72924aa48281b7ba39e837bb7bd1f46f23..01b2b51e4ab6c1af127292bc6eb7c172422ab781 100644 (file)
@@ -622,6 +622,18 @@ class TestLiterals(GrammarTest):
         self.validate(s)
 
 
+class TestPickleableException(unittest.TestCase):
+    def test_ParseError(self):
+        err = ParseError('msg', 2, None, (1, 'context'))
+        for proto in range(pickle.HIGHEST_PROTOCOL + 1):
+            err2 = pickle.loads(pickle.dumps(err, protocol=proto))
+            self.assertEqual(err.args, err2.args)
+            self.assertEqual(err.msg, err2.msg)
+            self.assertEqual(err.type, err2.type)
+            self.assertEqual(err.value, err2.value)
+            self.assertEqual(err.context, err2.context)
+
+
 def diff_texts(a, b, filename):
     a = a.splitlines()
     b = b.splitlines()
diff --git a/Misc/NEWS.d/next/Library/2018-11-25-20-05-33.bpo-35312.wbw0zO.rst b/Misc/NEWS.d/next/Library/2018-11-25-20-05-33.bpo-35312.wbw0zO.rst
new file mode 100644 (file)
index 0000000..c195468
--- /dev/null
@@ -0,0 +1 @@
+Make ``lib2to3.pgen2.parse.ParseError`` round-trip pickle-able.  Patch by Anthony Sottile.