Skip to content

feat: reuse weak callable proxy - #8618

Merged
youknowone merged 1 commit into
RustPython:mainfrom
rlaisqls:feat/weak-callable-proxy
Aug 30, 2026
Merged

youknowone merged 1 commit into
RustPython:mainfrom
rlaisqls:feat/weak-callable-proxy

Conversation

@rlaisqls

@rlaisqls rlaisqls commented Aug 30, 2026 •

Copy link
Copy Markdown
Contributor

One of checkbox below must be checked.

  • I did not use AI to write the code of this patch.
  • This PR follows our AI policy

Summary

  • Adds the missing weakcallableproxy type, so a proxy to a callable referent is itself callable, matching CPython's _PyWeakref_CallableProxyType.

  • weakref.CallableProxyType was only an alias for weakproxy, so weakref.proxy(callable_obj)() raised TypeError: 'weakproxy' object is not callable, and weakref.ProxyTypes held the same type twice.

  • PyWeakCallableProxy is a newtype over PyWeakProxy with base = PyWeakProxy: it inherits every proxy slot and only adds Callable, which forwards to the referent and raises ReferenceError once it is gone (as CPython's proxy_call)

Summary by CodeRabbit

  • New Features
    • Added callable weak-reference proxies that forward calls to their live referents.
    • Callable objects now automatically use the appropriate callable proxy type.
    • Updated weak-reference type reporting and proxy recognition to support callable proxies.

@youknowone
youknowone enabled auto-merge (squash) August 30, 2026 07:10
@coderabbitai

coderabbitai Bot commented Aug 30, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro Plus

Run ID: e8d356d0-90ee-46bd-ae8e-ce62b25704dc

📥 Commits

Reviewing files that changed from the base of the PR and between 6af309d and 6bbc9c1.

⛔ Files ignored due to path filters (1)
  • Lib/test/test_weakref.py is excluded by !Lib/**
📒 Files selected for processing (5)
  • crates/vm/src/builtins/mod.rs
  • crates/vm/src/builtins/weakproxy.rs
  • crates/vm/src/object/core.rs
  • crates/vm/src/stdlib/_weakref.rs
  • crates/vm/src/types/zoo.rs

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

The VM adds PyWeakCallableProxy, selects it for callable referents, registers it in TypeZoo, recognizes it during weakref handling, and exposes it through _weakref.CallableProxyType.

Changes

Callable weak proxy support

Layer / File(s) Summary
Callable proxy type and registration
crates/vm/src/builtins/weakproxy.rs, crates/vm/src/builtins/mod.rs, crates/vm/src/types/zoo.rs
Adds PyWeakCallableProxy, forwards calls to its referent, registers its VM type, and re-exports it from builtins.
Proxy selection and weakref classification
crates/vm/src/builtins/weakproxy.rs, crates/vm/src/object/core.rs
Selects the callable proxy for callable referents and recognizes both proxy types during reuse and weakref classification.
Stdlib callable proxy exposure
crates/vm/src/stdlib/_weakref.rs
Updates CallableProxyType to expose the callable weak proxy type.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to 6bbc9

The PR adds callable weak-reference proxies while preserving the existing weak-reference lifecycle and call dispatch behavior. No actionable merge-blocking risk remains beyond normal checks and review.

Sequence Diagram(s)

sequenceDiagram
  participant WeakrefAPI
  participant PyWeakProxy
  participant TypeZoo
  participant Referent
  WeakrefAPI->>PyWeakProxy: create weak proxy for Referent
  PyWeakProxy->>Referent: check callable status
  PyWeakProxy->>TypeZoo: select weakcallableproxy_type
  PyWeakProxy-->>WeakrefAPI: return PyWeakCallableProxy
  WeakrefAPI->>PyWeakProxy: invoke proxy
  PyWeakProxy->>Referent: upgrade and forward call
  Referent-->>WeakrefAPI: return result
Loading

Suggested reviewers: youknowone, shaharnaveh, bschoenmaeckers

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 37.50% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 5 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and directly describes the weak callable proxy reuse implemented by the pull request, including the addition and integration of the callable proxy type.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added the z-ca-2026 Tag to track Contribution Academy 2026 label Aug 30, 2026
@github-actions

Copy link
Copy Markdown
Contributor

📦 Library Dependencies

The following Lib/ modules were modified. Here are their dependencies:

[ ] lib: cpython/Lib/concurrent
[ ] test: cpython/Lib/test/test_concurrent_futures (TODO: 4)
[ ] test: cpython/Lib/test/test_interpreters
[ ] test: cpython/Lib/test/test__interpreters.py
[ ] test: cpython/Lib/test/test__interpchannels.py
[ ] test: cpython/Lib/test/test_crossinterp.py

dependencies:

  • concurrent (native: _crossinterp, _interpqueues, _interpreters, _queues, concurrent.futures, concurrent.futures._base, interpreter, itertools, multiprocessing.connection, multiprocessing.queues, multiprocessing.synchronize, process, sys, thread, time)
    • logging (native: atexit, collections.abc, email.message, email.utils, errno, http.client, logging.handlers, multiprocessing.queues, select, sys, time, urllib.parse, win32evtlog, win32evtlogutil)
    • multiprocessing (native: _multiprocessing, _posixshmem, _posixsubprocess, _winapi, array, atexit, collections.abc, connection, context, dummy, errno, forkserver, heap, itertools, managers, mmap, msvcrt, multiprocessing.connection, pool, popen_fork, popen_forkserver, popen_spawn_posix, popen_spawn_win32, queues, resource_sharer, resource_tracker, sharedctypes, spawn, synchronize, sys, time, util, xmlrpc.client)
    • pickle (native: _pickle, itertools, sys)
    • collections, functools, os, queue, threading, traceback, types, weakref

dependent tests: (17 tests)

  • concurrent: test_asyncio test_compileall test_concurrent_futures test_context test_genericalias test_inspect test_struct test_sys test_threading test_types test_wmi
    • asyncio: test_asyncio test_external_inspection test_logging test_os test_pdb test_unittest

[x] test: cpython/Lib/test/test_descr.py (TODO: 31)
[ ] test: cpython/Lib/test/test_descrtut.py (TODO: 3)

dependencies:

dependent tests: (no tests depend on descr)

[ ] test: cpython/Lib/test/test_class.py (TODO: 13)
[x] test: cpython/Lib/test/test_genericclass.py
[x] test: cpython/Lib/test/test_subclassinit.py

dependencies:

dependent tests: (no tests depend on class)

[x] test: cpython/Lib/test/test_cmd_line_script.py (TODO: 14)

dependencies:

dependent tests: (no tests depend on cmd_line_script)

[ ] test: cpython/Lib/test/test_import (TODO: 3)

dependencies:

dependent tests: (no tests depend on import)

[x] lib: cpython/Lib/weakref.py
[x] lib: cpython/Lib/_weakrefset.py
[x] test: cpython/Lib/test/test_weakref.py (TODO: 9)
[x] test: cpython/Lib/test/test_weakset.py

dependencies:

  • weakref

dependent tests: (224 tests)

  • weakref: test_array test_ast test_asyncio test_code test_concurrent_futures test_context test_contextlib test_copy test_ctypes test_deque test_descr test_dict test_enum test_exceptions test_file test_fileio test_finalization test_frame test_functools test_gc test_generators test_genericalias test_importlib test_inspect test_io test_ipaddress test_itertools test_logging test_memoryio test_memoryview test_mmap test_ordered_dict test_pickle test_picklebuffer test_queue test_re test_scope test_set test_slice test_socket test_sqlite3 test_ssl test_struct test_sys test_tempfile test_thread test_threading test_threading_local test_type_params test_types test_typing test_unicodedata test_unittest test_uuid test_weakref test_weakset test_xml_etree
    • asyncio: test_asyncio test_external_inspection test_os test_pdb test_unittest
    • bdb: test_bdb
    • concurrent: test_compileall test_concurrent_futures test_wmi
    • copy: test_bytes test_codecs test_collections test_copyreg test_coroutines test_csv test_decimal test_defaultdict test_dictviews test_email test_fractions test_http_cookies test_minidom test_opcache test_optparse test_platform test_plistlib test_posix test_site test_statistics test_structseq test_super test_sysconfig test_tomllib test_urllib2 test_xml_dom_minicompat test_zlib
      • argparse: test_argparse
      • collections: test_annotationlib test_bisect test_builtin test_c_locale_coercion test_call test_configparser test_contains test_ctypes test_embed test_exception_group test_fileinput test_funcattrs test_hash test_httpservers test_iter test_iterlen test_json test_math test_monitoring test_pathlib test_patma test_pprint test_pydoc test_random test_reprlib test_richcmp test_shelve test_sqlite3 test_string test_traceback test_tuple test_urllib test_userdict test_userlist test_userstring test_with
      • dataclasses: test__colorize test_ctypes test_regrtest test_zoneinfo
      • email.generator: test_email
      • gettext: test_gettext test_tools
      • http.cookiejar: test_http_cookiejar
      • http.server: test_robotparser test_urllib2_localnet test_xmlrpc
      • logging.handlers: test_pkgutil
      • mailbox: test_mailbox
      • smtplib: test_smtplib test_smtpnet
      • tarfile: test_shutil test_tarfile
      • webbrowser: test_webbrowser
    • inspect: test_abc test_asyncgen test_buffer test_clinic test_grammar test_ntpath test_operator test_posixpath test_signal test_turtle test_type_annotations test_yield_from test_zipimport test_zipimport_support
      • ast: test_codeop test_compile test_compiler_codegen test_dis test_fstring test_future_stmt test_peepholer test_peg_generator test_type_comments test_ucn test_unparse
      • cmd: test_cmd
      • importlib.metadata: test_importlib
      • pkgutil: test_pyrepl test_runpy
      • rlcompleter: test_pyrepl test_rlcompleter
      • trace: test_trace
    • logging: test_hashlib test_support test_urllib2net
      • hashlib: test_hmac
      • venv: test_venv
    • multiprocessing: test_fcntl test_multiprocessing_main_handling
    • symtable: test_symtable
    • tempfile: test_bz2 test_cmd_line test_cprofile test_ctypes test_doctest test_ensurepip test_faulthandler test_filecmp test_generated_cases test_importlib test_launcher test_linecache test_modulefinder test_peg_generator test_pkg test_pstats test_py_compile test_pyrepl test_selectors test_shlex test_string_literals test_subprocess test_sys_settrace test_tabnanny test_termios test_threadedtempfile test_tokenize test_urllib_response test_winconsoleio test_zipapp test_zipfile test_zipfile64 test_zstd
      • ctypes.util: test_ctypes
      • urllib.request: test_sax test_urllibnet

Legend:

  • [+] path exists in CPython
  • [x] up-to-date, [ ] outdated

@youknowone youknowone left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@youknowone
youknowone disabled auto-merge August 30, 2026 08:28
@youknowone
youknowone merged commit 1597e0a into RustPython:main Aug 30, 2026
29 of 30 checks passed
youknowone pushed a commit that referenced this pull request Sep 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

z-ca-2026 Tag to track Contribution Academy 2026

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants