-
-
Notifications
You must be signed in to change notification settings - Fork 417
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
equality of Tokens and strings is not transitive #1114
Comments
Thanks for floating this. I can see why this behavior would be an issue. Tokens behave so much like strings that it makes sense to assume they'll act like strings in every way.
Maybe you're right. Or maybe I should have just made Changing the subclassing isn't really an option. But, maybe changing Funny enough, the Lark-Cython implementation's only break in compatibility is that the Token class doesn't inherit from Anyway, I appreciate that you took the time to let me know. Maybe nothing will come of it, but we can keep it open and see what other people think. P.S. just realized that even if I fix |
I see two ways to restore transitivity of equality:
I don't have a good sense of how breaking either of these would be for lark and its users and I don't actually care about this very much myself. So I'm going to drop out and leave you to do with this what you will, thanks! |
Thanks again for your input! My intuition says that a subclass that divides the value space shouldn't be equal to its superclass. It's something I added out of convenience and didn't think much about. It might be a little too late to change it, at least for v1.x, but it's definitely something worth thinking more about. |
Describe the bug
The
__eq__
implementation forToken
gives non-transitive results: ie one can construct an example wherea == b
, andb == c
, buta != c
.To Reproduce
output
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
ormarkers__MARKER_NAME
- which caused some confusion.In an ideal world I think I'd argue that
Token
should not be a subclass ofstr
.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.
The text was updated successfully, but these errors were encountered: