Found while attempting to upgrade pydantic-core to test out PyO3 main.
Consider the following code from 0.22.
use pyo3::prelude::*;
pub trait Foo<'py>: ToPyObject {}
fn takes_foo<'py>(foo: impl Foo<'py>) {}
... this compiles fine, and is a useful pattern. Unfortunately, the upgrade path for this seems difficult in our current 0.23 draft.
Given the ToPyObject super trait (i.e. by-ref conversion), the simple thing I tried is:
use pyo3::prelude::*;
pub trait Foo<'py>
where
for<'a> &'a Self: IntoPyObject<'py>,
{
}
fn takes_foo<'py>(foo: impl Foo<'py>) {}
Unfortunately, this immediately blows up the compiler with a recursion error:
error[E0275]: overflow evaluating the requirement `&pyo3::Bound<'_, _>: pyo3::IntoPyObject<'_>`
|
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`pyo3_scratch`)
= note: required for `&&pyo3::Bound<'_, _>` to implement `pyo3::IntoPyObject<'_>`
= note: 126 redundant requirements hidden
= note: required for `&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&...` to implement `for<'a> pyo3::IntoPyObject<'py>`
= note: the full name for the type has been written to '/Users/david/Dev/pyo3-scratch/target/debug/deps/pyo3_scratch.long-type-2493199481127865716.txt'
= note: consider using `--verbose` to print the full type name to the console
Found while attempting to upgrade
pydantic-coreto test out PyO3main.Consider the following code from 0.22.
... this compiles fine, and is a useful pattern. Unfortunately, the upgrade path for this seems difficult in our current 0.23 draft.
Given the
ToPyObjectsuper trait (i.e. by-ref conversion), the simple thing I tried is:Unfortunately, this immediately blows up the compiler with a recursion error: