-
Notifications
You must be signed in to change notification settings - Fork 769
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 PyTypeMethods
#3705
implement PyTypeMethods
#3705
Conversation
4f08cdf
to
d790a5a
Compare
Let's make a decision about #3703 (comment) before reviewing this; if we agree to slow things down I'll remove the deprecations from here. |
Okay, rebased. To make the deprecation in the macro output conditional I added a Also, I'm really not feeling keen on |
IIRC, all |
f4e88ff
to
2344c90
Compare
CodSpeed Performance ReportMerging #3705 will degrade performances by 19.27%Comparing Summary
Benchmarks breakdown
|
Ok, this is finally reviewable! 🎉 |
I would like to review this, but it would be helpful if the conflicts were fixed first. |
Ahh aha as soon as I'd got it ready the new changes to |
Fixed! |
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 added one remark, otherwise this looks good to me 🚀
src/types/typeobject.rs
Outdated
/// This does not take ownership of the FFI pointer's "reference". The target type | ||
/// object will have its reference count increased by 1, which will be released when | ||
/// the `Bound` is dropped. |
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.
This does now take ownership, or did I misunderstand what you meant here?
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.
Uff, it's assuming that the reference is a borrowed pointer and creates a new reference. I agree my wording here was not the best.
Maybe it's better if we go a little bit inconsistent here and introduce this method with the new clearer name from_borrowed_type_ptr
(forget the bound bit)?
That'd then match the from_borrowed
methods which I think I'm about to introduce in a new PR...
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 pushed that as a new commit.
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.
This reads clearer to me 👍
Co-authored-by: Icxolu <10486322+Icxolu@users.noreply.github.com>
Co-authored-by: Lily Foote <code@lilyf.org>
🎉 thanks @adamreichold @Icxolu @LilyFoote - this was a thorny one and it feels like quite the milestone to finally get this one rounded out! |
src/types/typeobject.rs
Outdated
pub unsafe fn from_borrowed_type_ptr<'py>( | ||
py: Python<'py>, | ||
p: *mut ffi::PyTypeObject, | ||
) -> Bound<'py, PyType> { |
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.
pub unsafe fn from_borrowed_type_ptr<'py>( | |
py: Python<'py>, | |
p: *mut ffi::PyTypeObject, | |
) -> Bound<'py, PyType> { | |
pub unsafe fn from_borrowed_type_ptr( | |
py: Python<'_>, | |
p: *mut ffi::PyTypeObject, | |
) -> Bound<'_, PyType> { |
Split from #3606
This PR implements the
PyTypeMethods
trait and the bound variants of the constructors forPyType
.The most interesting thing in this PR is the bound variant of
PyType::from_type_ptr
, which I decided to introduce asPyType::from_type_ptr_borrowed
, because that pointer doesn't carry ownership.There's possibly arguments that one (or both) of the
PyType
constructors should not have bound variants introduced and we should rework the APIs, e.g.:PyType::new
in favour ofT::type_object
(orPython::get_type
)PyType::from_type_ptr_borrowed
less likestd::slice::from_raw_parts
, e.g. should it force a reference count increase?