overflow evaluating requirement for `&pyo3::Bound<'_, _>: pyo3::IntoPyObject<'_>`
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.2k
- Forks
- 1k
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 66
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the standalone Rust reproducer in the issue and compare the 0.22 ToPyObject pattern with the 0.23 IntoPyObject bound. Trace the recursive trait requirements reported by the compiler; done means an equivalent trait pattern compiles without overflow and provides a viable upgrade path. No source file or test is named.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, rust
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100