From f3eb62407b0ab98ba57906838e41f557c455ed06 Mon Sep 17 00:00:00 2001 From: David Hewitt Date: Thu, 14 Nov 2024 20:25:32 +0000 Subject: [PATCH] silence `non_upper_case_globals` lint on `__match_args__` (#4705) --- newsfragments/4705.fixed.md | 1 + pyo3-macros-backend/src/pyclass.rs | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 newsfragments/4705.fixed.md diff --git a/newsfragments/4705.fixed.md b/newsfragments/4705.fixed.md new file mode 100644 index 00000000000..b7f49d40b0d --- /dev/null +++ b/newsfragments/4705.fixed.md @@ -0,0 +1 @@ +Fix `non_upper_case_globals` lint firing for generated `__match_args__` on complex enums. diff --git a/pyo3-macros-backend/src/pyclass.rs b/pyo3-macros-backend/src/pyclass.rs index 2dd4cbfab2e..747c0153b95 100644 --- a/pyo3-macros-backend/src/pyclass.rs +++ b/pyo3-macros-backend/src/pyclass.rs @@ -1186,19 +1186,21 @@ fn impl_complex_enum_variant_match_args( variant_cls_type: &syn::Type, field_names: &mut Vec, ) -> (MethodAndMethodDef, syn::ImplItemConst) { + let ident = format_ident!("__match_args__"); let match_args_const_impl: syn::ImplItemConst = { let args_tp = field_names.iter().map(|_| { quote! { &'static str } }); parse_quote! { - const __match_args__: ( #(#args_tp,)* ) = ( + #[allow(non_upper_case_globals)] + const #ident: ( #(#args_tp,)* ) = ( #(stringify!(#field_names),)* ); } }; let spec = ConstSpec { - rust_ident: format_ident!("__match_args__"), + rust_ident: ident, attributes: ConstAttributes { is_class_attr: true, name: None,