Fix non_local_definitions lint triggers (#3955)
This commit is contained in:
parent
7cde95bba4
commit
989d2c53ab
|
@ -310,7 +310,7 @@ impl<'a> Container<'a> {
|
|||
}
|
||||
});
|
||||
quote!(
|
||||
match obj.extract() {
|
||||
match #pyo3_path::types::PyAnyMethods::extract(obj) {
|
||||
::std::result::Result::Ok((#(#field_idents),*)) => ::std::result::Result::Ok(#self_ty(#(#fields),*)),
|
||||
::std::result::Result::Err(err) => ::std::result::Result::Err(err),
|
||||
}
|
||||
|
@ -327,27 +327,29 @@ impl<'a> Container<'a> {
|
|||
let field_name = ident.to_string();
|
||||
let getter = match field.getter.as_ref().unwrap_or(&FieldGetter::GetAttr(None)) {
|
||||
FieldGetter::GetAttr(Some(name)) => {
|
||||
quote!(getattr(#pyo3_path::intern!(obj.py(), #name)))
|
||||
quote!(#pyo3_path::types::PyAnyMethods::getattr(obj, #pyo3_path::intern!(obj.py(), #name)))
|
||||
}
|
||||
FieldGetter::GetAttr(None) => {
|
||||
quote!(getattr(#pyo3_path::intern!(obj.py(), #field_name)))
|
||||
quote!(#pyo3_path::types::PyAnyMethods::getattr(obj, #pyo3_path::intern!(obj.py(), #field_name)))
|
||||
}
|
||||
FieldGetter::GetItem(Some(syn::Lit::Str(key))) => {
|
||||
quote!(get_item(#pyo3_path::intern!(obj.py(), #key)))
|
||||
quote!(#pyo3_path::types::PyAnyMethods::get_item(obj, #pyo3_path::intern!(obj.py(), #key)))
|
||||
}
|
||||
FieldGetter::GetItem(Some(key)) => {
|
||||
quote!(#pyo3_path::types::PyAnyMethods::get_item(obj, #key))
|
||||
}
|
||||
FieldGetter::GetItem(Some(key)) => quote!(get_item(#key)),
|
||||
FieldGetter::GetItem(None) => {
|
||||
quote!(get_item(#pyo3_path::intern!(obj.py(), #field_name)))
|
||||
quote!(#pyo3_path::types::PyAnyMethods::get_item(obj, #pyo3_path::intern!(obj.py(), #field_name)))
|
||||
}
|
||||
};
|
||||
let extractor = match &field.from_py_with {
|
||||
None => {
|
||||
quote!(#pyo3_path::impl_::frompyobject::extract_struct_field(&obj.#getter?, #struct_name, #field_name)?)
|
||||
quote!(#pyo3_path::impl_::frompyobject::extract_struct_field(&#getter?, #struct_name, #field_name)?)
|
||||
}
|
||||
Some(FromPyWithAttribute {
|
||||
value: expr_path, ..
|
||||
}) => {
|
||||
quote! (#pyo3_path::impl_::frompyobject::extract_struct_field_with(#expr_path as fn(_) -> _, &obj.#getter?, #struct_name, #field_name)?)
|
||||
quote! (#pyo3_path::impl_::frompyobject::extract_struct_field_with(#expr_path as fn(_) -> _, &#getter?, #struct_name, #field_name)?)
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -609,17 +611,11 @@ pub fn build_derive_from_pyobject(tokens: &DeriveInput) -> Result<TokenStream> {
|
|||
|
||||
let ident = &tokens.ident;
|
||||
Ok(quote!(
|
||||
// FIXME https://github.com/PyO3/pyo3/issues/3903
|
||||
#[allow(unknown_lints, non_local_definitions)]
|
||||
const _: () = {
|
||||
use #pyo3_path::prelude::PyAnyMethods;
|
||||
|
||||
#[automatically_derived]
|
||||
impl #trait_generics #pyo3_path::FromPyObject<#lt_param> for #ident #generics #where_clause {
|
||||
fn extract_bound(obj: &#pyo3_path::Bound<#lt_param, #pyo3_path::PyAny>) -> #pyo3_path::PyResult<Self> {
|
||||
#derives
|
||||
}
|
||||
}
|
||||
};
|
||||
))
|
||||
}
|
||||
|
|
|
@ -295,7 +295,7 @@ pub fn pymodule_function_impl(mut function: syn::ItemFn) -> Result<TokenStream>
|
|||
if function.sig.inputs.len() == 2 {
|
||||
module_args.push(quote!(module.py()));
|
||||
}
|
||||
module_args.push(quote!(::std::convert::Into::into(BoundRef(module))));
|
||||
module_args.push(quote!(::std::convert::Into::into(#pyo3_path::methods::BoundRef(module))));
|
||||
|
||||
let extractors = function
|
||||
.sig
|
||||
|
@ -330,21 +330,15 @@ pub fn pymodule_function_impl(mut function: syn::ItemFn) -> Result<TokenStream>
|
|||
// this avoids complications around the fact that the generated module has a different scope
|
||||
// (and `super` doesn't always refer to the outer scope, e.g. if the `#[pymodule] is
|
||||
// inside a function body)
|
||||
// FIXME https://github.com/PyO3/pyo3/issues/3903
|
||||
#[allow(unknown_lints, non_local_definitions)]
|
||||
const _: () = {
|
||||
use #pyo3_path::impl_::pymodule as impl_;
|
||||
use #pyo3_path::impl_::pymethods::BoundRef;
|
||||
|
||||
impl #ident::MakeDef {
|
||||
const fn make_def() -> #pyo3_path::impl_::pymodule::ModuleDef {
|
||||
fn __pyo3_pymodule(module: &#pyo3_path::Bound<'_, #pyo3_path::types::PyModule>) -> #pyo3_path::PyResult<()> {
|
||||
#ident(#(#module_args),*)
|
||||
}
|
||||
|
||||
impl #ident::MakeDef {
|
||||
const fn make_def() -> impl_::ModuleDef {
|
||||
const INITIALIZER: impl_::ModuleInitializer = impl_::ModuleInitializer(__pyo3_pymodule);
|
||||
const INITIALIZER: #pyo3_path::impl_::pymodule::ModuleInitializer = #pyo3_path::impl_::pymodule::ModuleInitializer(__pyo3_pymodule);
|
||||
unsafe {
|
||||
impl_::ModuleDef::new(
|
||||
#pyo3_path::impl_::pymodule::ModuleDef::new(
|
||||
#ident::__PYO3_NAME,
|
||||
#doc,
|
||||
INITIALIZER
|
||||
|
@ -352,7 +346,6 @@ pub fn pymodule_function_impl(mut function: syn::ItemFn) -> Result<TokenStream>
|
|||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -366,15 +366,11 @@ fn impl_class(
|
|||
.impl_all(ctx)?;
|
||||
|
||||
Ok(quote! {
|
||||
// FIXME https://github.com/PyO3/pyo3/issues/3903
|
||||
#[allow(unknown_lints, non_local_definitions)]
|
||||
const _: () = {
|
||||
impl #pyo3_path::types::DerefToPyAny for #cls {}
|
||||
|
||||
#pytypeinfo_impl
|
||||
|
||||
#py_class_impl
|
||||
};
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -794,9 +790,6 @@ fn impl_simple_enum(
|
|||
.impl_all(ctx)?;
|
||||
|
||||
Ok(quote! {
|
||||
// FIXME https://github.com/PyO3/pyo3/issues/3903
|
||||
#[allow(unknown_lints, non_local_definitions)]
|
||||
const _: () = {
|
||||
#pytypeinfo
|
||||
|
||||
#pyclass_impls
|
||||
|
@ -808,7 +801,6 @@ fn impl_simple_enum(
|
|||
#default_int
|
||||
#default_richcmp
|
||||
}
|
||||
};
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -933,9 +925,6 @@ fn impl_complex_enum(
|
|||
}
|
||||
|
||||
Ok(quote! {
|
||||
// FIXME https://github.com/PyO3/pyo3/issues/3903
|
||||
#[allow(unknown_lints, non_local_definitions)]
|
||||
const _: () = {
|
||||
#pytypeinfo
|
||||
|
||||
#pyclass_impls
|
||||
|
@ -951,7 +940,6 @@ fn impl_complex_enum(
|
|||
#(#variant_cls_pyclass_impls)*
|
||||
|
||||
#(#variant_cls_impls)*
|
||||
};
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -282,9 +282,6 @@ pub fn impl_wrap_pyfunction(
|
|||
// this avoids complications around the fact that the generated module has a different scope
|
||||
// (and `super` doesn't always refer to the outer scope, e.g. if the `#[pyfunction] is
|
||||
// inside a function body)
|
||||
// FIXME https://github.com/PyO3/pyo3/issues/3903
|
||||
#[allow(unknown_lints, non_local_definitions)]
|
||||
const _: () = {
|
||||
impl #name::MakeDef {
|
||||
const DEF: #pyo3_path::impl_::pymethods::PyMethodDef = #methoddef;
|
||||
}
|
||||
|
@ -292,6 +289,5 @@ pub fn impl_wrap_pyfunction(
|
|||
#[allow(non_snake_case)]
|
||||
#wrapper
|
||||
};
|
||||
};
|
||||
Ok(wrapped_pyfunction)
|
||||
}
|
||||
|
|
|
@ -170,9 +170,6 @@ pub fn impl_methods(
|
|||
};
|
||||
|
||||
Ok(quote! {
|
||||
// FIXME https://github.com/PyO3/pyo3/issues/3903
|
||||
#[allow(unknown_lints, non_local_definitions)]
|
||||
const _: () = {
|
||||
#(#trait_impls)*
|
||||
|
||||
#items
|
||||
|
@ -182,7 +179,6 @@ pub fn impl_methods(
|
|||
impl #ty {
|
||||
#(#associated_methods)*
|
||||
}
|
||||
};
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ struct Derive2(i32, i32); // tuple case
|
|||
#[allow(dead_code)]
|
||||
struct Derive3 {
|
||||
f: i32,
|
||||
#[pyo3(item(42))]
|
||||
g: i32,
|
||||
} // struct case
|
||||
|
||||
|
|
Loading…
Reference in New Issue