Skip to content

Commit

Permalink
Merge #2990 #2991
Browse files Browse the repository at this point in the history
2990: Fix `clippy::redundant_closure` lint firing for pyfunction defaults r=adamreichold a=davidhewitt

Fixes #2988

I'll push a follow-up for the FIXME as a separate PR.

2991: unpin 3.11 ci jobs r=adamreichold a=davidhewitt

With Python 3.11.2 released for a couple weeks now, I think #2817 is probably not an issue in CI any more.

Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
  • Loading branch information
bors[bot] and davidhewitt authored Feb 28, 2023
3 parents 410bb15 + 226bf97 + 0ef5531 commit 794755c
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 8 deletions.
9 changes: 3 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ jobs:
matrix:
extra-features: ["multiple-pymethods"]
rust: [stable]
# FIXME - pinned to 3.11.0 because 3.11.1 breaks CI on windows, see PyO3 issue 2817
python-version: ["3.11.0"]
python-version: ["3.11"]
platform:
[
{
Expand Down Expand Up @@ -177,8 +176,7 @@ jobs:
"3.8",
"3.9",
"3.10",
# FIXME - pinned to 3.11.0 because 3.11.1 breaks CI on windows, see PyO3 issue 2817
"3.11.0",
"3.11",
"pypy-3.7",
"pypy-3.8",
"pypy-3.9"
Expand Down Expand Up @@ -227,8 +225,7 @@ jobs:

# Test 32-bit Windows only with the latest Python version
- rust: stable
# FIXME - pinned to 3.11.0 because 3.11.1 breaks CI on windows, see PyO3 issue 2817
python-version: "3.11.0"
python-version: "3.11"
platform:
{
os: "windows-latest",
Expand Down
2 changes: 1 addition & 1 deletion .python-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.11.0
3.11
1 change: 1 addition & 0 deletions newsfragments/2990.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix `clippy::redundant_closure` lint on default arguments in `#[pyo3(signature = (...))]` annotations.
10 changes: 9 additions & 1 deletion pyo3-macros-backend/src/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,13 @@ fn impl_arg_param(
let tokens = if let Some(expr_path) = arg.attrs.from_py_with.as_ref().map(|attr| &attr.value) {
if let Some(default) = default {
quote_arg_span! {
_pyo3::impl_::extract_argument::from_py_with_with_default(#arg_value, #name_str, #expr_path, || #default)?
#[allow(clippy::redundant_closure)]
_pyo3::impl_::extract_argument::from_py_with_with_default(
#arg_value,
#name_str,
#expr_path,
|| #default
)?
}
} else {
quote_arg_span! {
Expand All @@ -220,6 +226,7 @@ fn impl_arg_param(
}
} else if arg.optional.is_some() {
quote_arg_span! {
#[allow(clippy::redundant_closure)]
_pyo3::impl_::extract_argument::extract_optional_argument(
#arg_value,
&mut { _pyo3::impl_::extract_argument::FunctionArgumentHolder::INIT },
Expand All @@ -229,6 +236,7 @@ fn impl_arg_param(
}
} else if let Some(default) = default {
quote_arg_span! {
#[allow(clippy::redundant_closure)]
_pyo3::impl_::extract_argument::extract_argument_with_default(
#arg_value,
&mut { _pyo3::impl_::extract_argument::FunctionArgumentHolder::INIT },
Expand Down
17 changes: 17 additions & 0 deletions tests/test_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1543,3 +1543,20 @@ fn test_option_pyclass_arg() {
.is_ok());
})
}

#[test]
#[allow(non_snake_case)] // FIXME __pyfunction__foo expanded symbol is not snake case
fn test_issue_2988() {
#[pyfunction]
#[pyo3(signature = (
_data = vec![],
_data2 = vec![],
))]
pub fn _foo(
_data: Vec<i32>,
// The from_py_with here looks a little odd, we just need some way
// to encourage the macro to expand the from_py_with default path too
#[pyo3(from_py_with = "PyAny::extract")] _data2: Vec<i32>,
) {
}
}

0 comments on commit 794755c

Please sign in to comment.