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

Added an as_bytes method for Py<PyBytes> #2235

Merged
merged 1 commit into from Mar 20, 2022
Merged

Conversation

alex
Copy link
Contributor

@alex alex commented Mar 19, 2022

No description provided.

src/types/bytes.rs Outdated Show resolved Hide resolved
@alex
Copy link
Contributor Author

alex commented Mar 19, 2022

Failing test is a network flake, can someone rerun those builds?

src/types/bytes.rs Outdated Show resolved Hide resolved
This allows for obtaining a slice that's not lexically bound to the GIL which can be helpful to avoid copying.
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.

Looks reasonable to me, thanks!

I think there's a few other immutable types like str and tuple which I guess can also have treatment like this where py is necessary for reading, but once read, the GIL can be released. Might be interesting to follow up this another time.

@messense messense merged commit b8dd626 into PyO3:main Mar 20, 2022
@alex alex deleted the pybytes-as-bytes branch March 20, 2022 12:43
@alex
Copy link
Contributor Author

alex commented Mar 20, 2022

Yes, I'm sure there's other cases where this pattern would be helpful -- I send this particularly because I have a use case in pyca/cryptography for this, where we'll be able to optimize some code to avoid allocations/copying now.

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.

None yet

5 participants