-
Notifications
You must be signed in to change notification settings - Fork 782
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
Add PyFrozenSetBuilder
#3156
Add PyFrozenSetBuilder
#3156
Conversation
9976903
to
0492768
Compare
clear()
, add()
, pop()
and discard()
for frozenset
The test failures seem to suggest that the methods do not actually modify a frozen set though? If that is the case, I would prefer not to add them as mutators which do not fail but do not mutate would be confusing at best. |
Hmm no they should. The docs make it clear they should work just like with a set. I also implemented |
From https://docs.python.org/3/c-api/set.html it looks like only Personally I think modifying frozensets is dangerous so would prefer to make this hard to use accidentally, whether by unsafe or just not exposing it. |
Is right before the list of these methods (including
I found it very useful in Pydantic 😅, I don't think it's that dangerous but I'd be okay with going with unsafe for now at least. |
clear()
, add()
, pop()
and discard()
for frozensetPyFrozenSet.add()
Okay, I left only
Interesting! I'd be +1 on doing the same thing for the tuple methods. I think marking them as |
I pondered this for a bit and while I would like us to add As an alternative I would like to propose adding @adriangb Would that suffice for the use cases you have in mind? |
That seems like a really good approach to me. |
I'm open to adding builders if we feel they're necessary, but first I wonder if we just need to improve the functionality of @adriangb I wonder why they're not meeting your needs? |
(Note that I'm not saying the |
I tried refactoring everything into an Iterator but it was unwieldy because:
|
The recent posts by withoutboats came to mind reading this and I agree that writing single use iterators is really cumbersome in today's Rust. If two small builder types let us work around that, I think that would be preferable as a short term solution. We could drop those again when generators have become a thing in Rust. |
That's very fair feedback, sorry if you invested a lot of time into trying the iterator approach @adriangb . I'm on board with us building the builders :) |
To be clear I’m not complaining, it’s not PyO3’s fault or anything, but thank you 😊
laughing at this, good one if it was intentional |
Since we agreed to pursue the builder approach, @adriangb do you have the bandwidth to just reboot this PR into adding the two builder types exposing |
I don’t have the bandwidth this weekend, but I think I can get to it late next week, and would like to do it you are willing to give me feedback. Just clarifying since you’re trying to make a release soon, I definitely would not plan on that/this being included. |
I added a builder for PyFrozenSet. I don't think we need one for non-frozen sets since it's always "safe" to add items, right? |
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.
👍 LGTM!
These are actually available via the C ABI. Since the distinction between set and frozenset means nothing to Rust safety, we should make these available