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

Why can't list[?str] support Eq ? #2095

Open
plajjan opened this issue Jan 19, 2025 · 0 comments
Open

Why can't list[?str] support Eq ? #2095

plajjan opened this issue Jan 19, 2025 · 0 comments

Comments

@plajjan
Copy link
Contributor

plajjan commented Jan 19, 2025

We had this code the other day where something produced a list[?str] and then we try to compare it like if my_list == ["a", "b"] and this doesn't compile... but I feel it should. I don't know exactly how, but it should. Clearly, if a list contains some None elements, it can't equal a list that only contains str. Similarly, for if foo == ["a", None], since the foo list starts with a None, then it's obvious that it won't equal the list we compare with since the first element "a" is a str, which clearly isn't None, so the overall result of this list comparison must be false. I don't understand enough of how Eq on a list works to know what needs to do what in order to support this, but it feels doable and all these checks around None are silly.

Everything could have a default Eq implementation that is the same as Identity, so if it's the actual same instance, then it's Eq==True, otherwise False. That would be enough to make the comparison in the example work and maybe it's useful for other things too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant