Repository: lark-parser/lark

Issue:
`lark.grammar.Symbol.__eq__` raises an `AssertionError` when checking if `None == Symbol(...)`
**Describe the bug**

When attempting to compare a variable set to `None` with a Symbol, Lark's implementation of `__eq__` within the `Symbol` class raises an `AssertionError`.

**To Reproduce**

```python
from lark.grammar import Symbol
a = None
b = Symbol("abc")

# this throws an error:
a == b
```

The error message:
```
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "[...]/venv/lib/python3.8/site-packages/lark/grammar.py", line 19, in __eq__
    assert isinstance(other, Symbol), other
AssertionError: None
```

Discussion:
@erezsh: This class is mainly for internal use, but I will accept a PR that returns False if the other object is None.


Solution patch:
diff --git a/lark/grammar.py b/lark/grammar.py
index 1d226d9e..016496bd 100644
--- a/lark/grammar.py
+++ b/lark/grammar.py
@@ -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):


Test patch:
diff --git a/tests/test_grammar.py b/tests/test_grammar.py
index 624b0799..52425db5 100644
--- a/tests/test_grammar.py
+++ b/tests/test_grammar.py
@@ -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):
@@ -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__':