From d41e3cdfb9c79cd09c5df10193e8a8dd46da6885 Mon Sep 17 00:00:00 2001 From: Louis Dubois Date: Wed, 23 Sep 2020 20:35:24 +0200 Subject: [PATCH] chg: Force pickle to use highest protocol Python2.7 uses protocol 1 by default, which is not compatible with class defining __slots__. On the other hand, all the Python versions support versions >= 2. --- lark/lark.py | 3 ++- tests/test_cache.py | 3 --- tests/test_trees.py | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/lark/lark.py b/lark/lark.py index ad60f04..d36343f 100644 --- a/lark/lark.py +++ b/lark/lark.py @@ -336,7 +336,8 @@ class Lark(Serialize): Useful for caching and multiprocessing. """ data, m = self.memo_serialize([TerminalDef, Rule]) - pickle.dump({'data': data, 'memo': m}, f) + pickle.dump({'data': data, 'memo': m}, f, + protocol=pickle.HIGHEST_PROTOCOL) @classmethod def load(cls, f): diff --git a/tests/test_cache.py b/tests/test_cache.py index ca4d781..1775e99 100644 --- a/tests/test_cache.py +++ b/tests/test_cache.py @@ -93,6 +93,3 @@ class TestCache(TestCase): if __name__ == '__main__': main() - - - diff --git a/tests/test_trees.py b/tests/test_trees.py index cca92f9..905ad5a 100644 --- a/tests/test_trees.py +++ b/tests/test_trees.py @@ -20,7 +20,7 @@ class TestTrees(TestCase): def test_pickle(self): s = copy.deepcopy(self.tree1) - data = pickle.dumps(s) + data = pickle.dumps(s, protocol=pickle.HIGHEST_PROTOCOL) assert pickle.loads(data) == s def test_repr_runnable(self):