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 path in from_py_with and deprecate string literal #4860

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Icxolu
Copy link
Contributor

@Icxolu Icxolu commented Jan 16, 2025

This allows specifying the from_py_with function as a path rather than a string literal. The old syntax is still valid and shows a deprecation warning.

Complementary to #4850.

@Icxolu Icxolu force-pushed the from-py-with branch 3 times, most recently from 5a5e09a to 8fdecc2 Compare January 17, 2025 17:12
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, 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;
}
Copy link
Member

Choose a reason for hiding this comment

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

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

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>) {}
Copy link
Member

Choose a reason for hiding this comment

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

so e.g. maybe here it says

use `bytes_from_py` instead of `"bytes_from_py"`

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.

2 participants