Skip to content

allow Bound<'_, T> in #[pymethods] self position#3896

Merged
davidhewitt merged 3 commits intoPyO3:mainfrom
Icxolu:bound-self
Feb 25, 2024
Merged

allow Bound<'_, T> in #[pymethods] self position#3896
davidhewitt merged 3 commits intoPyO3:mainfrom
Icxolu:bound-self

Conversation

@Icxolu
Copy link
Member

@Icxolu Icxolu commented Feb 24, 2024

Part of #3684

This allows extracting &Bound<'_, T> and Bound<'_, T> in #[pymethods] self position. This further discourages use of PyCell and makes Bound<'_, T> the primary type for interacting with Python objects.

@Icxolu Icxolu added the CI-skip-changelog Skip checking changelog entry label Feb 24, 2024
Copy link
Member

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching this one! I have a few small thoughts...

@@ -207,12 +207,11 @@ impl SelfType {
SelfType::TryFromPyCell(span) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be nice to rename this TryFromPyCell variant to TryFromBoundRef.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea!

Comment on lines +529 to +535
impl<'a, 'py, T: PyClass> TryFrom<BoundRef<'a, 'py, T>> for PyRef<'py, T> {
type Error = PyBorrowError;
#[inline]
fn try_from(value: BoundRef<'a, 'py, T>) -> Result<Self, Self::Error> {
value.0.clone().into_gil_ref().try_into()
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This .into_gil_ref() use here and below seems correct for now (and gets cleaned up after #3860) 👍

Bound::ref_from_ptr_or_opt(py, ptr).as_ref().map(BoundRef)
}

pub unsafe fn downcast<T: PyTypeCheck>(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd think this one is actually safe, given it's checked?

Suggested change
pub unsafe fn downcast<T: PyTypeCheck>(
pub fn downcast<T: PyTypeCheck>(

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your completely right, one of those copy pasta errors 😆 . I'll fix it

Copy link
Member

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect, thanks! 👍

@davidhewitt davidhewitt added this pull request to the merge queue Feb 24, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 24, 2024
@davidhewitt davidhewitt added this pull request to the merge queue Feb 24, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 24, 2024
@davidhewitt davidhewitt added this pull request to the merge queue Feb 25, 2024
Merged via the queue into PyO3:main with commit 7c10ff4 Feb 25, 2024
@Icxolu Icxolu deleted the bound-self branch February 25, 2024 09:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI-skip-changelog Skip checking changelog entry

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants