Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Symbol.__eq__ to return false when comparing with None #1481

Merged
merged 3 commits into from
Oct 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lark/grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ def __init__(self, name: str) -> None:
self.name = name

def __eq__(self, other):
assert isinstance(other, Symbol), other
if not isinstance(other, Symbol):
return NotImplemented
return self.is_term == other.is_term and self.name == other.name

def __ne__(self, other):
Expand Down
7 changes: 5 additions & 2 deletions tests/test_grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from lark import Lark, Token, Tree, ParseError, UnexpectedInput
from lark.load_grammar import GrammarError, GRAMMAR_ERRORS, find_grammar_errors, list_grammar_imports
from lark.load_grammar import FromPackageLoader

from lark.grammar import Symbol

class TestGrammar(TestCase):
def setUp(self):
Expand Down Expand Up @@ -296,8 +296,11 @@ def test_line_breaks(self):
p.parse('ab')


def test_symbol_eq(self):
a = None
b = Symbol("abc")


self.assertNotEqual(a, b)


if __name__ == '__main__':
Expand Down
Loading