Skip to content

Embedded _weakref semantics are incomplete for PyO3 weakref compatibility #7589

@smarcd

Description

@smarcd

Title: Embedded _weakref semantics are incomplete for PyO3 weakref compatibility

Using current RustPython tip (d201c48) through the PyO3 RustPython backend, the remaining weakref test failures narrow to _weakref semantics rather than generic backend bring-up.

Observed behavior:

  • PyWeakrefReference::upgrade() can work when backed by _weakref.ReferenceType
  • ReferenceType.__callback__ behavior appears wrong / missing
  • proxy / anyref upgrade paths still fail when routed through _weakref
  • these no longer go through stdlib weakref import recursion once the backend switches to _weakref

Representative PyO3 failures:

  • types::weakref::reference::tests::python_class::test_weakref_reference_behavior
    • fails on reference.getattr("__callback__") expecting None
  • types::weakref::anyref::tests::python_class::test_weakref_upgrade
    • fails because the generic weakref path cannot recover the referent from proxy/reference uniformly

Likely gap:

  • RustPython's built-in weakref / weakproxy public behavior does not yet fully match CPython / PyO3 expectations for:
    • ReferenceType.__callback__
    • proxy/reference upgrade interoperability through the C-API-compatible surface
    • possibly PyWeak / PyWeakProxy exposure through _weakref

Relevant RustPython files:

  • crates/vm/src/builtins/weakref.rs
  • crates/vm/src/builtins/weakproxy.rs
  • crates/vm/src/stdlib/_weakref.rs
  • crates/vm/src/object/core.rs

If helpful, I can follow up with a smaller RustPython-only repro, but this is currently the main remaining blocker for the PyO3 weakref test cluster.

Metadata

Metadata

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