Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix some nightly lints 2024-01-12 #3738

Merged
merged 1 commit into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions guide/src/class.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -96,6 +97,7 @@ impl Number {
Alternatively, if your `new` method may fail you can return `PyResult<Self>`.

```rust
# #![allow(dead_code)]
# use pyo3::prelude::*;
# use pyo3::exceptions::PyValueError;
# #[pyclass]
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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]
Expand Down
1 change: 1 addition & 0 deletions guide/src/class/object.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Recall the `Number` class from the previous chapter:

```rust
# #![allow(dead_code)]
use pyo3::prelude::*;

#[pyclass]
Expand Down
11 changes: 4 additions & 7 deletions pyo3-macros-backend/src/pyclass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
7 changes: 4 additions & 3 deletions pyo3-macros-backend/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<CrateAttribute>) -> 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(),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here nightly clippy didn't like the attr.as_ref().map(|attr| attr.value.0.clone()) and wanted attr.clone(), but I don't agree with that, because it's cloning more data than necessary.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new lint is way overly aggressive: rust-lang/rust-clippy#12135

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, it seems a bit broken. Thanks for filing that upstream 👍

None => syn::parse_str("::pyo3").unwrap(),
}
}

pub fn apply_renaming_rule(rule: RenamingRule, name: &str) -> String {
Expand Down
2 changes: 1 addition & 1 deletion src/tests/hygiene/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
1 change: 1 addition & 0 deletions tests/test_frompyobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
Loading