allow path in from_py_with and deprecate string literal#4860
Merged
allow path in from_py_with and deprecate string literal#4860
from_py_with and deprecate string literal#4860Conversation
5a5e09a to
8fdecc2
Compare
davidhewitt
approved these changes
Feb 28, 2025
Member
davidhewitt
left a comment
There was a problem hiding this comment.
Thanks, sorry for the slow review. I should be able to reliably be more active again now.
LGTM with one small suggestion before merge...
Comment on lines
+285
to
+290
| quote_spanned! { expr_path.span() => | ||
| #[deprecated(since = "0.24.0", note = "`from_py_with` string literals are deprecated. Use the function path instead.")] | ||
| #[allow(dead_code)] | ||
| const LIT_STR_DEPRECATION: () = (); | ||
| let _: () = LIT_STR_DEPRECATION; | ||
| } |
Member
There was a problem hiding this comment.
To avoid repetition, shall we put a helper function somewhere to produce these fragments?
Also, I wonder if we should be more direct with the hint to users. E.g.
= help: use `foo` instead of `"foo"`
(we could even substitute in the user input)
or maybe
remove the quotes from the literal
Member
Author
There was a problem hiding this comment.
Good idea! I made a small helper in utils and changed the deprecation message, let me know what you think
| warning: use of deprecated constant `__pyfunction_f::LIT_STR_DEPRECATION`: `from_py_with` string literals is deprecated. Use the function path instead. | ||
| --> tests/ui/invalid_argument_attributes.rs:23:28 | ||
| | | ||
| 23 | fn f(#[pyo3(from_py_with = "bytes_from_py")] _bytes: Vec<u8>) {} |
Member
There was a problem hiding this comment.
so e.g. maybe here it says
use `bytes_from_py` instead of `"bytes_from_py"`
9851988 to
d937436
Compare
davidhewitt
approved these changes
Mar 1, 2025
Member
davidhewitt
left a comment
There was a problem hiding this comment.
Looks great to me, thanks!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This allows specifying the
from_py_withfunction as a path rather than a string literal. The old syntax is still valid and shows a deprecation warning.Complementary to #4850.