From 94e242f51a351996d48a9dc72daf184f7086bd4f Mon Sep 17 00:00:00 2001 From: Gary Geng Date: Fri, 2 Apr 2021 15:14:16 -0500 Subject: [PATCH] Use NotImplemented for __eq__ and use __new__ for LexerThread --- lark/lexer.py | 10 ++++------ lark/parsers/lalr_parser.py | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/lark/lexer.py b/lark/lexer.py index d69db93..64dc33e 100644 --- a/lark/lexer.py +++ b/lark/lexer.py @@ -188,7 +188,7 @@ class LineCounter: def __eq__(self, other): if not isinstance(other, LineCounter): - return False + return NotImplemented return (self.newline_char == other.newline_char and self.char_pos == other.char_pos and self.line == other.line and self.column == other.column and self.line_start_pos == other.line_start_pos) @@ -414,7 +414,7 @@ class LexerState(object): def __eq__(self, other): if not isinstance(other, LexerState): - return False + return NotImplemented return (self.text == other.text and self.line_ctr == other.line_ctr and self.last_token == other.last_token) @@ -481,10 +481,8 @@ class LexerThread(object): return self.lexer.lex(self.state, parser_state) def __copy__(self): - copied = type(self)( - self.lexer, - '' - ) + copied = object.__new__(LexerThread) + copied.lexer = self.lexer copied.state = copy(self.state) return copied ###} diff --git a/lark/parsers/lalr_parser.py b/lark/parsers/lalr_parser.py index 2d3e559..6fc76ea 100644 --- a/lark/parsers/lalr_parser.py +++ b/lark/parsers/lalr_parser.py @@ -94,7 +94,7 @@ class ParserState(object): # Necessary for match_examples() to work def __eq__(self, other): if not isinstance(other, ParserState): - return False + return NotImplemented return len(self.state_stack) == len(other.state_stack) and self.position == other.position def __copy__(self):