-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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: string subclass overriding eq #15735
base: master
Are you sure you want to change the base?
Conversation
d265d0e
to
b1701a7
Compare
Heya, I was going to review this pull request, but it fell off my radar. Sorry about that! The test should be using an interpreted str subclass, ie. one that is not compiled (take a closer look at the original issue): [case testCustomCompare]
from interp import S
def test_custom_compare() -> None:
s: str = S("x")
assert not s == "x"
assert not "x" == s
[file interp.py]
class S(str):
def __eq__(self, other: object) -> bool:
return False I couldn't get it to work properly with |
Thank you very much for pointing me out. I managed to write a dedicated function for ne comparison. One is the C function Then, in the I also did my best to improve the test data, with the folloqing two classes:
I import them from a different file as you stated, I'm sorry I misunderstood that aspect of the issue. I'm available for improvements, I hope this can be useful. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Co-authored-by: Richard Si <[email protected]>
Co-authored-by: Richard Si <[email protected]>
Co-authored-by: Richard Si <[email protected]>
Thank you very much @ichard26 for the review! I applied your modifications. Ragarding optimization, I would say that the check on likelyness could be an overhead.
I don't know if there is any way/necessity to let the user specify a parameter to avoid such check (thus resorting to the "risky" version in which no check on the real class is done). In case there was a chance to let such parameter be passed during code generation, that could become some compiler directives to avoid the generation of such if, maybe. I leave this idea as a pour parler, the only options I found were in |
Fixes mypyc/mypyc#973
In order to avoid problem when subclasses inheriting from string and overriding
__eq__
I applied the code from @ichard26 :This is a draft pull request. Main problem is that I has to create a special case in
mypyc/irbuild/prepare.py
to allow for a class inheriting from a string:otherwise the error
"Inheriting from most builtin types is unimplemented"
would have occurred. That's why I addedThat's why I think it's worth to evaluate if this isn't too much a of a "risky" thing in the codebase.
If everything makes sense, I would keep on going by adding some minor documentation.
A basic test has been added.
Thanks for the attention.