Open
Conversation
Add get_callback() method to PyWeak in core.rs that safely reads the callback field under the stripe lock. Expose it as a read-only __callback__ property on the weakref type, matching CPython behavior: - Returns the callback function when one was provided and referent is alive - Returns None when no callback was provided - Returns None after the referent has been collected - Raises AttributeError on assignment (read-only) Remove @unittest.expectedFailure from test_callback_attribute and test_callback_attribute_after_deletion in test_weakref.py. Add regression tests to extra_tests/snippets/stdlib_weakref.py. Agent-Logs-Url: https://github.com/RustPython/RustPython/sessions/a8689daa-4476-4645-a935-0e13c7f7bb42 Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix embedded weakref semantics for PyO3 compatibility
Add Apr 13, 2026
__callback__ property to weakref type
Contributor
📦 Library DependenciesThe following Lib/ modules were modified. Here are their dependencies: [x] lib: cpython/Lib/weakref.py dependencies:
dependent tests: (205 tests)
Legend:
|
Member
|
@copilot Fix CI failure |
Agent-Logs-Url: https://github.com/RustPython/RustPython/sessions/4995198f-e083-4dac-823a-166fcf54adc4 Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
RustPython's
weakreftype was missing the__callback__read-only property, blocking PyO3 weakref compatibility (e.g.reference.getattr("__callback__")fails).Changes
crates/vm/src/object/core.rs: Addget_callback()toPyWeak— reads the callback field under the stripe lock using the same double-check pattern asupgrade()crates/vm/src/builtins/weakref.rs: Expose__callback__as a read-only#[pygetset]Lib/test/test_weakref.py: RemoveexpectedFailurefromtest_callback_attributeandtest_callback_attribute_after_deletionextra_tests/snippets/stdlib_weakref.py: Add regression coverageSemantics match CPython: returns the callback if alive,
Noneif no callback was set or referent was collected (callback consumed during clear).