summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorAnthony Sottile <asottile@umich.edu>2018-11-27 18:39:49 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2018-11-27 18:39:49 (GMT)
commitc57e6e2e52d5d8b4005753bed789d99ebe407fb6 (patch)
tree3ef4b574f1a50ca526ce31184ce39824b28c029b /Lib
parentd4f9cf5545d6d8844e0726552ef2e366f5cc3abd (diff)
downloadcpython-c57e6e2e52d5d8b4005753bed789d99ebe407fb6.zip
cpython-c57e6e2e52d5d8b4005753bed789d99ebe407fb6.tar.gz
cpython-c57e6e2e52d5d8b4005753bed789d99ebe407fb6.tar.bz2
bpo-35312: Make lib2to3.pgen2.parse.ParseError round-trip pickle-able. (GH-10710)
Diffstat (limited to 'Lib')
-rw-r--r--Lib/lib2to3/pgen2/parse.py3
-rw-r--r--Lib/lib2to3/tests/test_parser.py12
2 files changed, 15 insertions, 0 deletions
diff --git a/Lib/lib2to3/pgen2/parse.py b/Lib/lib2to3/pgen2/parse.py
index 6bebdbb..cf3fcf7 100644
--- a/Lib/lib2to3/pgen2/parse.py
+++ b/Lib/lib2to3/pgen2/parse.py
@@ -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.
diff --git a/Lib/lib2to3/tests/test_parser.py b/Lib/lib2to3/tests/test_parser.py
index 829e5a7..01b2b51 100644
--- a/Lib/lib2to3/tests/test_parser.py
+++ b/Lib/lib2to3/tests/test_parser.py
@@ -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()