Skip to content

Commit 28dc143

Browse files
authored
remove deprecated from_py_with string variant (PyO3#5097)
1 parent 61f43e8 commit 28dc143

File tree

13 files changed

+19
-170
lines changed

13 files changed

+19
-170
lines changed

newsfragments/5097.removed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
removed support for the deprecated string from of `from_py_with`

pyo3-macros-backend/src/attributes.rs

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -350,37 +350,7 @@ impl<K: ToTokens, V: ToTokens> ToTokens for OptionalKeywordAttribute<K, V> {
350350
}
351351
}
352352

353-
#[derive(Debug, Clone)]
354-
pub struct ExprPathWrap {
355-
pub from_lit_str: bool,
356-
pub expr_path: ExprPath,
357-
}
358-
359-
impl Parse for ExprPathWrap {
360-
fn parse(input: ParseStream<'_>) -> Result<Self> {
361-
match input.parse::<ExprPath>() {
362-
Ok(expr_path) => Ok(ExprPathWrap {
363-
from_lit_str: false,
364-
expr_path,
365-
}),
366-
Err(e) => match input.parse::<LitStrValue<ExprPath>>() {
367-
Ok(LitStrValue(expr_path)) => Ok(ExprPathWrap {
368-
from_lit_str: true,
369-
expr_path,
370-
}),
371-
Err(_) => Err(e),
372-
},
373-
}
374-
}
375-
}
376-
377-
impl ToTokens for ExprPathWrap {
378-
fn to_tokens(&self, tokens: &mut TokenStream) {
379-
self.expr_path.to_tokens(tokens)
380-
}
381-
}
382-
383-
pub type FromPyWithAttribute = KeywordAttribute<kw::from_py_with, ExprPathWrap>;
353+
pub type FromPyWithAttribute = KeywordAttribute<kw::from_py_with, ExprPath>;
384354
pub type IntoPyWithAttribute = KeywordAttribute<kw::into_py_with, ExprPath>;
385355

386356
pub type DefaultAttribute = OptionalKeywordAttribute<Token![default], Expr>;

pyo3-macros-backend/src/frompyobject.rs

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::attributes::{
22
self, get_pyo3_options, CrateAttribute, DefaultAttribute, FromPyWithAttribute,
33
RenameAllAttribute, RenamingRule,
44
};
5-
use crate::utils::{self, deprecated_from_py_with, Ctx};
5+
use crate::utils::{self, Ctx};
66
use proc_macro2::TokenStream;
77
use quote::{format_ident, quote, quote_spanned, ToTokens};
88
use syn::{
@@ -304,13 +304,10 @@ impl<'a> Container<'a> {
304304
value: expr_path,
305305
}) = from_py_with
306306
{
307-
let deprecation = deprecated_from_py_with(expr_path).unwrap_or_default();
308-
309307
let extractor = quote_spanned! { kw.span =>
310308
{ let from_py_with: fn(_) -> _ = #expr_path; from_py_with }
311309
};
312310
quote! {
313-
#deprecation
314311
Ok(#self_ty {
315312
#ident: #pyo3_path::impl_::frompyobject::extract_struct_field_with(#extractor, obj, #struct_name, #field_name)?
316313
})
@@ -327,13 +324,10 @@ impl<'a> Container<'a> {
327324
value: expr_path,
328325
}) = from_py_with
329326
{
330-
let deprecation = deprecated_from_py_with(expr_path).unwrap_or_default();
331-
332327
let extractor = quote_spanned! { kw.span =>
333328
{ let from_py_with: fn(_) -> _ = #expr_path; from_py_with }
334329
};
335330
quote! {
336-
#deprecation
337331
#pyo3_path::impl_::frompyobject::extract_tuple_struct_field_with(#extractor, obj, #struct_name, 0).map(#self_ty)
338332
}
339333
} else {
@@ -367,14 +361,7 @@ impl<'a> Container<'a> {
367361
}}
368362
});
369363

370-
let deprecations = struct_fields
371-
.iter()
372-
.filter_map(|fields| fields.from_py_with.as_ref())
373-
.filter_map(|kw| deprecated_from_py_with(&kw.value))
374-
.collect::<TokenStream>();
375-
376364
quote!(
377-
#deprecations
378365
match #pyo3_path::types::PyAnyMethods::extract(obj) {
379366
::std::result::Result::Ok((#(#field_idents),*)) => ::std::result::Result::Ok(#self_ty(#(#fields),*)),
380367
::std::result::Result::Err(err) => ::std::result::Result::Err(err),
@@ -448,13 +435,7 @@ impl<'a> Container<'a> {
448435
fields.push(quote!(#ident: #extracted));
449436
}
450437

451-
let d = struct_fields
452-
.iter()
453-
.filter_map(|field| field.from_py_with.as_ref())
454-
.filter_map(|kw| deprecated_from_py_with(&kw.value))
455-
.collect::<TokenStream>();
456-
457-
quote!(#d ::std::result::Result::Ok(#self_ty{#fields}))
438+
quote!(::std::result::Result::Ok(#self_ty{#fields}))
458439
}
459440
}
460441

pyo3-macros-backend/src/params.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::utils::{deprecated_from_py_with, Ctx, TypeExt as _};
1+
use crate::utils::{Ctx, TypeExt as _};
22
use crate::{
33
attributes::FromPyWithAttribute,
44
method::{FnArg, FnSpec, RegularArg},
@@ -62,9 +62,7 @@ pub fn impl_arg_params(
6262
.filter_map(|(i, arg)| {
6363
let from_py_with = &arg.from_py_with()?.value;
6464
let from_py_with_holder = format_ident!("from_py_with_{}", i);
65-
let d = deprecated_from_py_with(from_py_with).unwrap_or_default();
6665
Some(quote_spanned! { from_py_with.span() =>
67-
#d
6866
let #from_py_with_holder = #from_py_with;
6967
})
7068
})

pyo3-macros-backend/src/pymethod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use std::ffi::CString;
44
use crate::attributes::{FromPyWithAttribute, NameAttribute, RenamingRule};
55
use crate::method::{CallingConvention, ExtractErrorMode, PyArg};
66
use crate::params::{impl_regular_arg_param, Holders};
7-
use crate::utils::{deprecated_from_py_with, PythonDoc, TypeExt as _};
87
use crate::utils::{Ctx, LitCStr};
8+
use crate::utils::{PythonDoc, TypeExt as _};
99
use crate::{
1010
method::{FnArg, FnSpec, FnType, SelfType},
1111
pyfunction::PyFunctionOptions,
@@ -659,10 +659,8 @@ pub fn impl_py_setter_def(
659659
let (from_py_with, ident) =
660660
if let Some(from_py_with) = &value_arg.from_py_with().as_ref().map(|f| &f.value) {
661661
let ident = syn::Ident::new("from_py_with", from_py_with.span());
662-
let d = deprecated_from_py_with(from_py_with).unwrap_or_default();
663662
(
664663
quote_spanned! { from_py_with.span() =>
665-
#d
666664
let #ident = #from_py_with;
667665
},
668666
ident,

pyo3-macros-backend/src/utils.rs

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use crate::attributes::{CrateAttribute, ExprPathWrap, RenamingRule};
1+
use crate::attributes::{CrateAttribute, RenamingRule};
22
use proc_macro2::{Span, TokenStream};
3-
use quote::{quote, quote_spanned, ToTokens};
3+
use quote::{quote, ToTokens};
44
use std::ffi::CString;
55
use syn::spanned::Spanned;
66
use syn::{punctuated::Punctuated, Token};
@@ -324,20 +324,6 @@ pub(crate) fn has_attribute_with_namespace(
324324
})
325325
}
326326

327-
pub(crate) fn deprecated_from_py_with(expr_path: &ExprPathWrap) -> Option<TokenStream> {
328-
let path = quote!(#expr_path).to_string();
329-
let msg =
330-
format!("remove the quotes from the literal\n= help: use `{path}` instead of `\"{path}\"`");
331-
expr_path.from_lit_str.then(|| {
332-
quote_spanned! { expr_path.span() =>
333-
#[deprecated(since = "0.24.0", note = #msg)]
334-
#[allow(dead_code)]
335-
const LIT_STR_DEPRECATION: () = ();
336-
let _: () = LIT_STR_DEPRECATION;
337-
}
338-
})
339-
}
340-
341327
pub(crate) trait TypeExt {
342328
/// Replaces all explicit lifetimes in `self` with elided (`'_`) lifetimes
343329
///

tests/test_compile_error.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,4 @@ fn test_compile_errors() {
7373
t.compile_fail("tests/ui/invalid_base_class.rs");
7474
t.pass("tests/ui/ambiguous_associated_items.rs");
7575
t.pass("tests/ui/pyclass_probe.rs");
76-
t.compile_fail("tests/ui/deprecated.rs");
7776
}

tests/ui/deprecated.rs

Lines changed: 0 additions & 37 deletions
This file was deleted.

tests/ui/deprecated.stderr

Lines changed: 0 additions & 33 deletions
This file was deleted.

tests/ui/invalid_argument_attributes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ fn from_py_with_string(#[pyo3("from_py_with")] _param: String) {}
1313
fn from_py_with_value_not_found(#[pyo3(from_py_with = func)] _param: String) {}
1414

1515
#[pyfunction]
16-
fn from_py_with_repeated(#[pyo3(from_py_with = "func", from_py_with = "func")] _param: String) {}
16+
fn from_py_with_repeated(#[pyo3(from_py_with = func, from_py_with = func)] _param: String) {}
1717

1818
fn bytes_from_py(bytes: &Bound<'_, pyo3::types::PyBytes>) -> Vec<u8> {
1919
bytes.as_bytes().to_vec()

0 commit comments

Comments
 (0)