Skip to content

Backports for 0.29.3 - #6353

Open
felipebalbi wants to merge 1 commit into
PyO3:release-0.29from
felipebalbi:backport-6309
Open

Backports for 0.29.3#6353
felipebalbi wants to merge 1 commit into
PyO3:release-0.29from
felipebalbi:backport-6309

Conversation

@felipebalbi

Copy link
Copy Markdown

Running list of things to backport for a 0.29.3:

#6309 fixed #6308 (clippy::clone_on_copy firing on the FromPyObject impl
generated for #[pyclass(from_py_object)] types that are also Copy). It merged
to main on 2026-08-08, three days after 0.29.2 shipped, so it isn't in any
release and release-0.29 doesn't have it.

Why this might be worth a patch release

When #6308 was filed the lint was nightly-only. It is now in beta: I reproduced
it on 1.99.0-beta.1, which promotes to stable on 2026-10-01. At that point any
crate that puts #[pyclass(from_py_object)] on a Copy type and runs
cargo clippy -- -D warnings in CI starts failing. Confirmed affected on the
current release (0.29.2, from crates.io), not just older 0.29.x.

Known affected downstreams: pyca/cryptography (the original report) and
OpenDevicePartnership/pico-de-gallo.

I appreciate 0.30 may not be far off. If it is likely to land before 2026-10-01
then this probably isn't worth a patch release, and I'm happy to close this.

The backport

Both source hunks cherry-picked cleanly and are byte-identical to #6309 --
PyClassGuard, PyClassGuardError and FromPyObject all already exist on
release-0.29, so extract_pyclass_with_clone compiles there unchanged. The
regression test from #6309 (Copy on MyEnum in tests/test_enum.rs) came
across too.

The only conflicts were tests/ui/invalid_pyclass_args.{default,inspect}.stderr,
and they conflicted on unrelated divergence between main and release-0.29
rather than on this fix. I did not hand-merge them: I reset both to the
release-0.29 baseline and regenerated with UI_TEST=bless across all three
feature combos from nox -s update-ui-tests. The result is 6 lines, all
pyo3::FromPyObject -> FromPyObject, which is just rustc shortening the
diagnostic path now that FromPyObject is imported in src/impl_/pyclass.rs.
Nothing semantic.

Verified locally on 1.98.0 stable and 1.99.0-beta.1:

  • UI tests before blessing: 54 passed, 1 failed, and the single failure was
    exactly the expected file -- so these snapshots are not platform-sensitive here.
  • UI tests after blessing: 55 passed on each of macros, full, abi3,full.
  • cargo test --test test_enum --features full: 24 passed.
  • Beta clippy on test_enum: clean. Reverting just the macro one-liner brings
    back using 'clone' on type 'MyEnum' which implements the 'Copy' trait, so the
    regression test is doing real work.
  • cargo fmt --all --check: clean.

Two CI notes

The changelog check will fail. The newsfragment is 6309.fixed.md, keeping the
original PR number so the entry reads correctly in the 0.29.3 notes, but
check-changelog looks for a fragment named after this PR. Happy to rename it,
add a second one, or you can apply CI-skip-changelog -- whichever you prefer.

Beta clippy also flags clippy::nonnull_unchecked_on_box_ptr in
src/internal_tricks.rs:56 on this branch. That is pre-existing on
release-0.29 and unrelated to this backport; noting it only so it isn't
attributed to this change. The clippy/beta job is continue-on-error, so it
should not block.


Disclosure per Contributing.md: I used AI assistance to locate the upstream fix,
perform the cherry-pick, and run the verification above. The code is an
unmodified cherry-pick of #6309 with the UI snapshots regenerated by the
project's own bless tooling; authorship on the commit is preserved as
@alex via cherry-pick -x.

…`Copy` classes (PyO3#6309)

* fix `clippy::clone_on_copy` firing on `#[pyclass(from_py_object)]` + `Copy` classes

Move the clone out of the generated `FromPyObject` impl into a generic
helper where the type is only known to be `Clone`, so the lint cannot
trigger. Fixes PyO3#6308.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* bless UI test snapshot for trimmed `FromPyObject` diagnostic paths

The generated `extract` body no longer references `FromPyObject` items
inline, which changes how rustc renders the trait path in unrelated
diagnostics in the same crate.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* bless `default` revision UI test snapshot as well

Same trimmed-path diagnostic drift as the `inspect` revision; this
snapshot only runs without `experimental-inspect` enabled.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
(cherry picked from commit 1914ce3)
@felipebalbi
felipebalbi marked this pull request as ready for review August 26, 2026 16:26
@codspeed-hq

codspeed-hq Bot commented Aug 26, 2026

Copy link
Copy Markdown

Hooray! CodSpeed harness just leveled up!

The base and head of this comparison were measured with different runner settings, so their benchmark values are not directly comparable.

What changed between base and head:

Re-run the base with the same settings to get a valid performance comparison.


Comparing felipebalbi:backport-6309 (582b916) with release-0.29 (646a38d)1

Open in CodSpeed

Footnotes

  1. No successful run was found on release-0.29 (a70d17f) during the generation of this report, so e69ae19 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants