fix some nightly lints 2024-01-12

This commit is contained in:
David Hewitt 2024-01-12 10:05:30 +00:00
parent 4b172874dc
commit 4504a7c96e
6 changed files with 15 additions and 11 deletions

View File

@ -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. attribute. Only Python's `__new__` method can be specified, `__init__` is not available.
```rust ```rust
# #![allow(dead_code)]
# use pyo3::prelude::*; # use pyo3::prelude::*;
# #[pyclass] # #[pyclass]
# struct Number(i32); # struct Number(i32);
@ -96,6 +97,7 @@ impl Number {
Alternatively, if your `new` method may fail you can return `PyResult<Self>`. Alternatively, if your `new` method may fail you can return `PyResult<Self>`.
```rust ```rust
# #![allow(dead_code)]
# use pyo3::prelude::*; # use pyo3::prelude::*;
# use pyo3::exceptions::PyValueError; # use pyo3::exceptions::PyValueError;
# #[pyclass] # #[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: The next step is to create the module initializer and add our class to it:
```rust ```rust
# #![allow(dead_code)]
# use pyo3::prelude::*; # use pyo3::prelude::*;
# #[pyclass] # #[pyclass]
# struct Number(i32); # 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: To create a constructor which takes a positional class argument, you can combine the `#[classmethod]` and `#[new]` modifiers:
```rust ```rust
# #![allow(dead_code)]
# use pyo3::prelude::*; # use pyo3::prelude::*;
# use pyo3::types::PyType; # use pyo3::types::PyType;
# #[pyclass] # #[pyclass]

View File

@ -3,6 +3,7 @@
Recall the `Number` class from the previous chapter: Recall the `Number` class from the previous chapter:
```rust ```rust
# #![allow(dead_code)]
use pyo3::prelude::*; use pyo3::prelude::*;
#[pyclass] #[pyclass]

View File

@ -885,13 +885,10 @@ impl<'a> PyClassImplsBuilder<'a> {
let cls = self.cls; let cls = self.cls;
let doc = self.doc.as_ref().map_or(quote! {"\0"}, |doc| quote! {#doc}); let doc = self.doc.as_ref().map_or(quote! {"\0"}, |doc| quote! {#doc});
let is_basetype = self.attr.options.subclass.is_some(); let is_basetype = self.attr.options.subclass.is_some();
let base = self let base = match &self.attr.options.extends {
.attr Some(extends_attr) => extends_attr.value.clone(),
.options None => parse_quote! { _pyo3::PyAny },
.extends };
.as_ref()
.map(|extends_attr| extends_attr.value.clone())
.unwrap_or_else(|| parse_quote! { _pyo3::PyAny });
let is_subclass = self.attr.options.extends.is_some(); let is_subclass = self.attr.options.extends.is_some();
let is_mapping: bool = self.attr.options.mapping.is_some(); let is_mapping: bool = self.attr.options.mapping.is_some();
let is_sequence: bool = self.attr.options.sequence.is_some(); let is_sequence: bool = self.attr.options.sequence.is_some();

View File

@ -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`). /// Extract the path to the pyo3 crate, or use the default (`::pyo3`).
pub(crate) fn get_pyo3_crate(attr: &Option<CrateAttribute>) -> syn::Path { pub(crate) fn get_pyo3_crate(attr: &Option<CrateAttribute>) -> syn::Path {
attr.as_ref() match attr {
.map(|p| p.value.0.clone()) Some(attr) => attr.value.0.clone(),
.unwrap_or_else(|| syn::parse_str("::pyo3").unwrap()) None => syn::parse_str("::pyo3").unwrap(),
}
} }
pub fn apply_renaming_rule(rule: RenamingRule, name: &str) -> String { pub fn apply_renaming_rule(rule: RenamingRule, name: &str) -> String {

View File

@ -2,7 +2,7 @@
#[derive(crate::FromPyObject)] #[derive(crate::FromPyObject)]
#[pyo3(crate = "crate")] #[pyo3(crate = "crate")]
struct Derive1(i32); // newtype case struct Derive1(#[allow(dead_code)] i32); // newtype case
#[derive(crate::FromPyObject)] #[derive(crate::FromPyObject)]
#[pyo3(crate = "crate")] #[pyo3(crate = "crate")]

View File

@ -420,6 +420,7 @@ TypeError: failed to extract enum Foo ('TupleVar | StructVar | TransparentTuple
#[derive(Debug, FromPyObject)] #[derive(Debug, FromPyObject)]
enum EnumWithCatchAll<'a> { enum EnumWithCatchAll<'a> {
#[allow(dead_code)]
#[pyo3(transparent)] #[pyo3(transparent)]
Foo(Foo<'a>), Foo(Foo<'a>),
#[pyo3(transparent)] #[pyo3(transparent)]