-
Notifications
You must be signed in to change notification settings - Fork 763
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
RFC: Provide a special purpose FromPyObject impl for byte slices #2899
Conversation
5fffb8e
to
8393bfc
Compare
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.
LGTM, please add some tests though 🙂
Certainly, and also a changelog entry. I just wanted to discuss whether we really want this hack and where we need to document it. The doc comment on the impl would only be visible in the implementors section of |
8393bfc
to
014c513
Compare
Sneaky! I think this seems reasonable, perhaps we should also add into-py conversions for I think I would also try to make this discoverable in the guide, maybe both from https://pyo3.rs/v0.18.0/conversions/tables and on a new page discussing performance techniques? (I've been thinking about adding a performance page for ages anyway.) I wonder, should we also ban |
You specifically mean banning (I think raising an error in |
This seems more worthy of a lint than a compile error.
We'd check whether the type looks like |
So
I will adjust the table. I would ask for the performance section to be a separate PR which I will try to produce in reasonable amount of time (if no one else does so first). The reason is that I expect the wording to be somewhat contentions as we probably all care very much about performance and the techniques in question can be subtle and their applicability depend on a lot of context. |
3c31073
to
d8546ba
Compare
Potentially also The symmetry is an interesting feature. It's quite pretty, but I think it has a risk of surprising users? They are likely not going to think too hard what variant their As an alternative, how about changing the I feel more strongly about narrowing the to-python value to be |
And yes, @mejrs is right on what I was thinking to do for |
d8546ba
to
cbc4eae
Compare
Done.
Implemented, but this is conditional not using the limited API or Python 3.11 or later. It also not clear how to include this in the guide.
I would still prefer a lint then, especially if this is imprecise due to working with syntax only. (I would also suggest a separate PR as well since this one seems to sprawl somewhat.) One related idea that is a bit out in the woods: Since for |
cbc4eae
to
f4b2198
Compare
Note that there's no stable way to do lints from macros, so any lints are a clumsy hack like what we do with deprecations.
It's an interesting thought and might work nicely, we could have
Ah, I had overlooked |
I was just thinking about that too. Maybe time for an RFC? |
691dc1c
to
228cfd0
Compare
@adamreichold what's your feeling about this currently? I think I regret my suggestion of After that, probably good to merge this? (We could leave an issue in the backlog to remind ourselves to widen this conversion in a few years when 3.10 is dropped?) |
Yes, I think we should start with the simplest possible version and extend it after we have gathered further feedback. I intentionally added the buffer protocol support as a separate commit which I will drop from the PR.
Yes, I think so.
Yes, will do. |
228cfd0
to
fb3450b
Compare
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.
Looks great, thanks!
bors r+
2899: RFC: Provide a special purpose FromPyObject impl for byte slices r=davidhewitt a=adamreichold This enables efficiently and safely getting a byte slice from either bytes or byte arrays. The main issue I see here is discoverability, i.e. should this be mention in the docs of `PyBytes` and `PyByteArray` or in the guide? It is also not completely clear whether this really _fixes_ the issue. Closes #2888 Co-authored-by: Adam Reichold <[email protected]>
Concerning the build error, I am not sure how the builtin |
… get a byte slice from either bytes or byte arrays.
… as well as function arguments.
…ing native code instead inline Python.
fb3450b
to
0a48859
Compare
Canceled. |
Added a commit to use native code instead of inline Python for the type assertions. bors r=davidhewitt |
I think probably this is related to #2891 somehow. Needs some investigation. Using |
Build succeeded: |
This enables efficiently and safely getting a byte slice from either bytes or byte arrays.
The main issue I see here is discoverability, i.e. should this be mention in the docs of
PyBytes
andPyByteArray
or in the guide?It is also not completely clear whether this really fixes the issue.
Closes #2888