-
Notifications
You must be signed in to change notification settings - Fork 760
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
implement PartialEq<str>
for Bound<'py, PyString>
#4245
Conversation
Thanks for the approval @LilyFoote! I just realised: there's a bit of an edge case here: what about when the What should we do then? One option is to make these implementations return false for subclasses (e.g. do an In I'm inclined to proceed with this as-is, but I would also be glad to hear folks' opinions as there is a slight possibility this is a footgun which leads to surprises in the subclass edge case. |
I think subclassing built-in types like |
True! I think to that point, it's very likely that users would write Any other opinions before we proceed? |
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.
I agree here. I think it is reasonable to expect PyString
to do normal string comparison and having the PartialEq
impls makes a lot of code much more ergonomic and readable. Documenting this behavior seems sufficient.
Thanks both! I've added documentation and will proceed to merge 👍 |
Idea spurred by #4020 and also what I've just been doing in #4196.
This PR implements comparison between Python
str
and Rust&str
by using:PyUnicode_EqualToUTF8AndSize
on Python 3.13,&str
and doing equality that way on older versions.PyUnicode_EqualToUTF8AndSize
can never fail, so similarly the fallback implementations just returnfalse
on error getting UTF8 data out.