Skip to content

Conversation

@Icxolu
Copy link
Contributor

@Icxolu Icxolu commented Oct 22, 2025

This emits a deprecation warning on #[pyclass]es that are affected by the FromPyObject + Clone blanket impl. It uses a Probe to detect the Clone impl and conditionally emits the deprecation. This ensures only types are flagged that are actually affected by the change. The deprecation can be suppressed by specifying either the skip_from_py_object or from_py_object option.

With this in 0.28, I think we can remove the blanket impl in 0.29.

#5419

@Icxolu Icxolu force-pushed the deprecate-frompyobject-blanket branch from 36cd3f7 to 762ef5f Compare October 22, 2025 16:58
Copy link
Member

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

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

Thanks, generally looks great to me, nice touch to only emit it on types which are actually Clone!

I think also worth noting in the migration guide?

|
= note: available fields are: `0`, `1`, `2`

warning: use of deprecated associated constant `pyo3::impl_::deprecated::DeprecatedFromPyObjectBlanket::<true>::MSG`: Implicit by value extraction of pyclasses is deprecated. Use `from_py_object` to keep the current behaviour or `skip_from_py_object` to opt-out.
Copy link
Member

Choose a reason for hiding this comment

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

I feel like it would be helpful here to make the hint a bit clearer that this is applicable to classes which implement `Clone.

Maybe something like the following (note I renamed the struct too given it shows in the public error message):

Suggested change
warning: use of deprecated associated constant `pyo3::impl_::deprecated::DeprecatedFromPyObjectBlanket::<true>::MSG`: Implicit by value extraction of pyclasses is deprecated. Use `from_py_object` to keep the current behaviour or `skip_from_py_object` to opt-out.
warning: use of deprecated associated constant `pyo3::impl_::deprecated::HasAutomaticFromPyObject::<true>::MSG`: The automatically derived `FromPyObject` implementation for `#[pyclass]` types which implement `Clone` is being phased out. Use `from_py_object` to keep the automatic derive or `skip_from_py_object` to accept the new behaviour.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good to me!

@Icxolu Icxolu force-pushed the deprecate-frompyobject-blanket branch from 762ef5f to 3e0c463 Compare October 26, 2025 21:35
@davidhewitt davidhewitt enabled auto-merge October 26, 2025 22:17
@davidhewitt davidhewitt added this pull request to the merge queue Oct 26, 2025
Merged via the queue into PyO3:main with commit c7c3c53 Oct 26, 2025
41 of 42 checks passed
@Icxolu Icxolu deleted the deprecate-frompyobject-blanket branch October 27, 2025 17:31
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