From 4504a7c96e52c120e07842158784ac86cfbbb977 Mon Sep 17 00:00:00 2001 From: David Hewitt Date: Fri, 12 Jan 2024 10:05:30 +0000 Subject: [PATCH] fix some nightly lints 2024-01-12 --- guide/src/class.md | 4 ++++ guide/src/class/object.md | 1 + pyo3-macros-backend/src/pyclass.rs | 11 ++++------- pyo3-macros-backend/src/utils.rs | 7 ++++--- src/tests/hygiene/misc.rs | 2 +- tests/test_frompyobject.rs | 1 + 6 files changed, 15 insertions(+), 11 deletions(-) diff --git a/guide/src/class.md b/guide/src/class.md index e3f35027..25df536c 100644 --- a/guide/src/class.md +++ b/guide/src/class.md @@ -80,6 +80,7 @@ To declare a constructor, you need to define a method and annotate it with the ` attribute. Only Python's `__new__` method can be specified, `__init__` is not available. ```rust +# #![allow(dead_code)] # use pyo3::prelude::*; # #[pyclass] # struct Number(i32); @@ -96,6 +97,7 @@ impl Number { Alternatively, if your `new` method may fail you can return `PyResult`. ```rust +# #![allow(dead_code)] # use pyo3::prelude::*; # use pyo3::exceptions::PyValueError; # #[pyclass] @@ -130,6 +132,7 @@ For arguments, see the [`Method arguments`](#method-arguments) section below. The next step is to create the module initializer and add our class to it: ```rust +# #![allow(dead_code)] # use pyo3::prelude::*; # #[pyclass] # struct Number(i32); @@ -663,6 +666,7 @@ Declares a class method callable from Python. To create a constructor which takes a positional class argument, you can combine the `#[classmethod]` and `#[new]` modifiers: ```rust +# #![allow(dead_code)] # use pyo3::prelude::*; # use pyo3::types::PyType; # #[pyclass] diff --git a/guide/src/class/object.md b/guide/src/class/object.md index cfaa8bb1..5d4f53a1 100644 --- a/guide/src/class/object.md +++ b/guide/src/class/object.md @@ -3,6 +3,7 @@ Recall the `Number` class from the previous chapter: ```rust +# #![allow(dead_code)] use pyo3::prelude::*; #[pyclass] diff --git a/pyo3-macros-backend/src/pyclass.rs b/pyo3-macros-backend/src/pyclass.rs index f60dbe5f..66f41504 100644 --- a/pyo3-macros-backend/src/pyclass.rs +++ b/pyo3-macros-backend/src/pyclass.rs @@ -885,13 +885,10 @@ impl<'a> PyClassImplsBuilder<'a> { let cls = self.cls; let doc = self.doc.as_ref().map_or(quote! {"\0"}, |doc| quote! {#doc}); let is_basetype = self.attr.options.subclass.is_some(); - let base = self - .attr - .options - .extends - .as_ref() - .map(|extends_attr| extends_attr.value.clone()) - .unwrap_or_else(|| parse_quote! { _pyo3::PyAny }); + let base = match &self.attr.options.extends { + Some(extends_attr) => extends_attr.value.clone(), + None => parse_quote! { _pyo3::PyAny }, + }; let is_subclass = self.attr.options.extends.is_some(); let is_mapping: bool = self.attr.options.mapping.is_some(); let is_sequence: bool = self.attr.options.sequence.is_some(); diff --git a/pyo3-macros-backend/src/utils.rs b/pyo3-macros-backend/src/utils.rs index 360b1ec2..0fc96bd6 100644 --- a/pyo3-macros-backend/src/utils.rs +++ b/pyo3-macros-backend/src/utils.rs @@ -146,9 +146,10 @@ pub fn unwrap_ty_group(mut ty: &syn::Type) -> &syn::Type { /// Extract the path to the pyo3 crate, or use the default (`::pyo3`). pub(crate) fn get_pyo3_crate(attr: &Option) -> syn::Path { - attr.as_ref() - .map(|p| p.value.0.clone()) - .unwrap_or_else(|| syn::parse_str("::pyo3").unwrap()) + match attr { + Some(attr) => attr.value.0.clone(), + None => syn::parse_str("::pyo3").unwrap(), + } } pub fn apply_renaming_rule(rule: RenamingRule, name: &str) -> String { diff --git a/src/tests/hygiene/misc.rs b/src/tests/hygiene/misc.rs index 2e7d3e6f..66db7f3a 100644 --- a/src/tests/hygiene/misc.rs +++ b/src/tests/hygiene/misc.rs @@ -2,7 +2,7 @@ #[derive(crate::FromPyObject)] #[pyo3(crate = "crate")] -struct Derive1(i32); // newtype case +struct Derive1(#[allow(dead_code)] i32); // newtype case #[derive(crate::FromPyObject)] #[pyo3(crate = "crate")] diff --git a/tests/test_frompyobject.rs b/tests/test_frompyobject.rs index 30edf6f7..aa0c1cef 100644 --- a/tests/test_frompyobject.rs +++ b/tests/test_frompyobject.rs @@ -420,6 +420,7 @@ TypeError: failed to extract enum Foo ('TupleVar | StructVar | TransparentTuple #[derive(Debug, FromPyObject)] enum EnumWithCatchAll<'a> { + #[allow(dead_code)] #[pyo3(transparent)] Foo(Foo<'a>), #[pyo3(transparent)]