Skip to content
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

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

Merged
merged 3 commits into from
Feb 25, 2024

Conversation

Icxolu
Copy link
Contributor

@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
Contributor 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) 👍

@@ -490,6 +492,12 @@ impl<'a, 'py> BoundRef<'a, 'py, PyAny> {
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
Contributor 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
39 of 40 checks passed
@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