Skip to content

Conversation

@jakelishman
Copy link
Contributor

The additional PyArray methods try_into_readonly and try_into_readwrite allow directly moving the ownership of the Bound pointer backing a PyArray into the relevant view type. This both a) avoids reference counting overhead and b) allows methods on PyReadwriteArray (like resize) that require unique pointer referencing, not just unique active borrows to function without the user having to manually drop the base guard.

Fix #522

The additional `PyArray` methods `try_into_readonly` and
`try_into_readwrite` allow directly moving the ownership of the `Bound`
pointer backing a `PyArray` into the relevant view type.  This both a)
avoids reference counting overhead and b) allows methods on
`PyReadwriteArray` (like `resize`) that _require_ unique pointer
referencing, not just unique active borrows to function without the user
having to manually drop the base guard.
Copy link
Contributor

@Icxolu Icxolu left a comment

Choose a reason for hiding this comment

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

Adding these is reasonable I think. Left a couple of small comments. Adding a changelog entry would be great.

@jakelishman
Copy link
Contributor Author

I've added a changelog entry in adb0811 and stuck a use of into_readonly into one of the tests in be438e7 so the coverage goal gets met.

Copy link
Contributor

@Icxolu Icxolu left a comment

Choose a reason for hiding this comment

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

Thank you!

@Icxolu Icxolu merged commit f454b99 into PyO3:main Jan 7, 2026
76 checks passed
@jakelishman jakelishman deleted the pyarray_into branch January 7, 2026 22:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test regressions with numpy 2.4.0

2 participants