-
-
Notifications
You must be signed in to change notification settings - Fork 452
Description
Describe the bug
The __eq__ implementation for Token gives non-transitive results: ie one can construct an example where a == b, and b == c, but a != c.
To Reproduce
from lark import Token
a = Token("noun", "flies")
b = "flies"
c = Token("verb", "flies")
print(f"a == b ? {a == b}")
print(f"b == c ? {b == c}")
print(f"a == c ? {a == c}")output
a == b ? True
b == c ? True
a == c ? False
This report is prompted by python-poetry/poetry-core#286, in which one lark grammar is reused by another. So depending on which was used you could get the "same" thing with type either MARKER_NAME or markers__MARKER_NAME - which caused some confusion.
In an ideal world I think I'd argue that Token should not be a subclass of str.
I suspect this is too deeply embedded / relied upon, and that you're not going to want to do anything about this. That's fine by me, please just close this out. But I thought I'd open the issue anyway so that you knew this of this oddity and could take that decision deliberately.