Skip to content

Test Failures due to PyO3 API Changes #1

@Amitkumar282

Description

@Amitkumar282

Description

Multiple test failures are observed due to API changes in .
The issues are reproducible on x86_64, indicating they are not architecture-specific.

Issues

1. Type Mismatch (Breaking Change)

expected Result<&PyAny, PyErr>
found Result<Bound<'_, PyAny>, PyErr>

Caused by transition from &PyAny → Bound<'py, PyAny>

2. Deprecated API Usage

.downcast() → deprecated (use Bound::cast / downcast_bound)
Python::with_gil → deprecated (use Python::attach)

3. Method Resolution Failures

no method named call1 for &PyAny
no method named is_instance_of
no method named set_item for &PyDict

Indicates incompatibility with newer PyO3 types

4. Downcasting Errors

no method named downcast for Py<T>
Suggested replacement: downcast_bound

5. Ownership & Borrowing Issues

Temporary value dropped while borrowed (E0716)
use of moved value (E0382)

Due to the new ownership model with Bound<'py, T>

6. Argument / Signature Mismatches

expected &PyDict, found Bound<'_, PyDict>
Function signatures incompatible with updated API

Root Cause:

These issues stem from PyO3’s migration to a safer API using Bound<'py, T> instead of borrowed references (&PyAny, &PyDict), along with related method and lifetime handling changes.

Proposed Solution:

We think that with the above failures, these changes may get it working:

  1. Replace &PyAny with Bound<'_, PyAny> in function signatures.
  2. Replace &PyDict with Bound<'_, PyDict> in function signatures.
  3. Change .downcast() to .downcast_bound() when calling on a Py.
  4. Pass &bound_object (by reference) to methods like contains or append.
  5. Break up long method chains (like getattr(...).downcast(...)) into two steps using a let binding.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions