From 138f1d5d76d1a98e2489cb12503ec907fb6f6ed5 Mon Sep 17 00:00:00 2001 From: Parker <6646825+psboyce@users.noreply.github.com> Date: Sat, 14 Apr 2018 23:10:28 -0600 Subject: [PATCH] Fix order of members when pickling Token I found this while porting Token to C, essentially the value and pos_in_stream members of Token were swapped in ``__reduce__``, which means running ``pickle.loads`` and ``pickle.dumps`` would result in unpickled tokens whose value was the original's position in stream, and vice versa. In my C extension this caused a TypeError exception, but the behavior will have to be corrected in both. --- lark/lexer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lark/lexer.py b/lark/lexer.py index 0a46ee1..938d22b 100644 --- a/lark/lexer.py +++ b/lark/lexer.py @@ -41,7 +41,7 @@ class Token(Str): return cls(type_, value, borrow_t.pos_in_stream, line=borrow_t.line, column=borrow_t.column) def __reduce__(self): - return (self.__class__, (self.type, self.pos_in_stream, self.value, self.line, self.column, )) + return (self.__class__, (self.type, self.value, self.pos_in_stream, self.line, self.column, )) def __repr__(self): return 'Token(%s, %r)' % (self.type, self.value)