-
Notifications
You must be signed in to change notification settings - Fork 806
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 Bound
constructor for PyBool
#3790
Conversation
Thank you yet again 👍 I'm a bit under the weather this evening so I'll do my best to read and review first thing in the morning. |
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.
Thanks, this looks like the right design to me! I think the __ne__
implementation probably needs to create a "new reference" using .to_owned()
, otherwise I have mostly just added comments of approval and very tiny nits.
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.
Thanks again, looks good to me!
We're getting pretty close to having this API be feature-complete now! I think there will still be a long tail of adjustments and refactoring, but users can hopefully start playing with this before long 🚀
/// This returns a [`Borrowed`] reference to one of Pythons `True` or | ||
/// `False` singletons | ||
#[inline] | ||
pub fn new_bound(py: Python<'_>, val: bool) -> Borrowed<'_, '_, Self> { |
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.
Sorry for being late to the party: If these are singletons, shouldn't the first lifetime even be 'static
, i.e.
pub fn new_bound(py: Python<'py>, val: bool) -> Borrowed<'static, 'py, Self>;
or are they still bound to the interpreter?
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 wondered about this, I think while static is possibly fine I preferred having this limited to the interpreter. Just in case this becomes relevant for things like subinterpreters in the future.
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 guess we can always expand this later if users have a need.
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 thought about this too, but it seemed safer to go with this option now, and relax it in the future if possible.
Part of #3684
This adds the
Bound
constructors forPyBool
.Since the ffi types
Py_True
andPy_False
are singletons pointing into static memory, this returnBorrowed
instead ofBound
. I choose to still keep the namenew_bound
for consistency with the other type. SinceBorrowed
derefs into&Bound
it also behaves very similarly.