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

Weird clippy issue when vecs are used in signature #2988

Closed
iajoiner opened this issue Feb 26, 2023 · 2 comments · Fixed by #2990
Closed

Weird clippy issue when vecs are used in signature #2988

iajoiner opened this issue Feb 26, 2023 · 2 comments · Fixed by #2990
Labels

Comments

@iajoiner
Copy link
Contributor

Bug Description

Clippy produces weird warning when vec is used in signature. Moreover it is impossible to turn that warning off at the level of the function.

Steps to Reproduce

use pyo3::prelude::*;

#[pyfunction]
#[pyo3(signature = (
    _data = vec![],
))]
pub fn foo(
    _data: Vec<i32>,
) {
}

Put the code above in a new binary or lib crate and run cargo clippy.

You should see a warning like this:

Checking pycatch v0.1.0 (/home/iajoiner/Documents/tests/pycatch)
warning: redundant closure
 --> src/main.rs:6:13
  |
6 |       _data = vec![],
  |  _____________^
7 | | ))]
8 | | pub fn foo(
9 | |     _data: Vec<i32>,
  | |______________^ help: replace the closure with `Vec::new`: `std::vec::Vec::new`
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure
  = note: `#[warn(clippy::redundant_closure)]` on by default

warning: `pycatch` (bin "pycatch") generated 1 warning
    Finished dev [unoptimized + debuginfo] target(s) in 0.07s

Backtrace

No response

Your operating system and version

Ubuntu 22.04

Your Python version (python --version)

Python 3.10.6

Your Rust version (rustc --version)

rustc 1.67.1 (d5a82bbd2 2023-02-07)

Your PyO3 version

0.18.1

How did you install python? Did you use a virtualenv?

I think it came with Ubuntu.
Yes.

Additional Info

No response

@iajoiner
Copy link
Contributor Author

Corresponding clippy issue: rust-lang/rust-clippy#10378

@davidhewitt
Copy link
Member

Thanks for the report! PyO3 places this default into a closure in the generated code, so the lint is correctly identifying a case which looks like it could technically be reduced if handwritten. In practice I think there's not much we can do except silence the warning, which #2990 implements.

@bors bors bot closed this as completed in 794755c Feb 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants