Browse Source

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.
tags/gm/2021-09-23T00Z/github.com--lark-parser-lark/0.11.0
Louis Dubois 4 years ago
committed by Erez Sh
parent
commit
c6f2b023f3
3 changed files with 3 additions and 5 deletions
  1. +2
    -1
      lark/lark.py
  2. +0
    -3
      tests/test_cache.py
  3. +1
    -1
      tests/test_trees.py

+ 2
- 1
lark/lark.py View File

@@ -336,7 +336,8 @@ class Lark(Serialize):
Useful for caching and multiprocessing. Useful for caching and multiprocessing.
""" """
data, m = self.memo_serialize([TerminalDef, Rule]) 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 @classmethod
def load(cls, f): def load(cls, f):


+ 0
- 3
tests/test_cache.py View File

@@ -93,6 +93,3 @@ class TestCache(TestCase):


if __name__ == '__main__': if __name__ == '__main__':
main() main()




+ 1
- 1
tests/test_trees.py View File

@@ -20,7 +20,7 @@ class TestTrees(TestCase):


def test_pickle(self): def test_pickle(self):
s = copy.deepcopy(self.tree1) s = copy.deepcopy(self.tree1)
data = pickle.dumps(s)
data = pickle.dumps(s, protocol=pickle.HIGHEST_PROTOCOL)
assert pickle.loads(data) == s assert pickle.loads(data) == s


def test_repr_runnable(self): def test_repr_runnable(self):


Loading…
Cancel
Save