implement PartialEq<str> for Bound<'py, PyString>#4245
implement PartialEq<str> for Bound<'py, PyString>#4245davidhewitt merged 4 commits intoPyO3:mainfrom
PartialEq<str> for Bound<'py, PyString>#4245Conversation
|
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? |
Icxolu
left a comment
There was a problem hiding this comment.
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
strand Rust&strby using:PyUnicode_EqualToUTF8AndSizeon Python 3.13,&strand doing equality that way on older versions.PyUnicode_EqualToUTF8AndSizecan never fail, so similarly the fallback implementations just returnfalseon error getting UTF8 data out.