Skip to content

Implement PEP 814 frozendict - #8951

Draft
youknowdot wants to merge 1 commit into
RustPython:mainfrom
youknowdot:cpython-315-frozendict
Draft

youknowdot wants to merge 1 commit into
RustPython:mainfrom
youknowdot:cpython-315-frozendict

Conversation

@youknowdot

Copy link
Copy Markdown

Summary

Implement the builtin frozendict from PEP 814, characterized against CPython 3.15.0rc2.

  • Own immutable dictionary storage directly, with shared dict views/iterators, cached order-independent hashing, subclass-aware construction and unions, copy/deepcopy, pickle, and GC support
  • Support frozen globals in eval/exec and frame/function APIs, preserving readonly function.__globals__ member layout; accept frozen type namespaces through a mutable class-namespace copy
  • Extend existing dictionary C-API reads and eval/frame APIs; reject writes without exposing mutable backing storage
  • Add 58 original Python regressions exercised by four Rust integration tests, and remove two now-passing dict expected-failure markers without changing their assertions

The C-API work follows this crate's abi3/abi3t scope. New non-limited CPython PyFrozenDict_* exports and type statics remain outside its current ABI architecture.

Validation

  • Workspace Rust tests: 1,349 passed, 18 ignored
  • C-API tests: 120 passed, 4 ignored
  • All 58 original regressions pass on RustPython and CPython 3.15.0rc2, with no skips
  • 39 unchanged rc2 dict/view/copy tests: pass, with one upstream CPython-only skip; equivalent hashing assertions also run in the native suite
  • Release stdlib tests: 831 tests across dict, dictviews, copy, builtin, types, funcattrs, frame, generators, coroutines, and asyncgen; 43 existing skips
  • Full snippet run: 467 passed, 13 failed. Twelve failures are sandbox multiprocessing/filesystem restrictions also observed with host CPython; one needs the optional SQLite feature omitted by the default build
  • Workspace and C-API Clippy: clean; normal pre-commit hooks pass
  • The limited-stack deep-repr and nested-map stress crashes in unoptimized dev mode also reproduce on an exact clean base build; both pass in the feature's optimized test/release builds

AI-assisted with OpenAI Codex: implementation, regression tests, review, and local validation.

Add dictionary-owned frozen mapping storage, shared views and cached hashing, read-only execution globals, type namespace support, and stable dictionary C-API coverage. Add differential regressions against CPython 3.15rc2.

Assisted-by: Codex:model-version-unavailable
@coderabbitai

coderabbitai Bot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


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 commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

📦 Library Dependencies

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

[x] test: cpython/Lib/test/test_dict.py (TODO: 2)
[x] test: cpython/Lib/test/test_dictcomps.py (TODO: 1)
[x] test: cpython/Lib/test/test_dictviews.py (TODO: 1)
[x] test: cpython/Lib/test/test_userdict.py
[x] test: cpython/Lib/test/mapping_tests.py

dependencies:

dependent tests: (no tests depend on dict)

[ ] lib: cpython/Lib/copy.py
[x] test: cpython/Lib/test/test_copy.py

dependencies:

  • copy
    • copyreg, types, weakref

dependent tests: (324 tests)

  • copy: test_array test_ast test_bytes test_code test_codecs test_collections test_copy test_copyreg test_coroutines test_csv test_decimal test_defaultdict test_deque test_descr test_dictviews test_email test_enum test_exceptions test_fractions test_frame test_functools test_generators test_genericalias test_http_cookies test_inspect test_ipaddress test_itertools test_logging test_memoryview test_minidom test_opcache test_optparse test_ordered_dict test_platform test_plistlib test_posix test_re test_set test_site test_slice test_statistics test_structseq test_super test_sysconfig test_tomllib test_types test_typing test_unittest test_urllib2 test_uuid test_weakref test_weakset test_xml_dom_minicompat test_xml_etree test_zlib
    • argparse: test_argparse
      • ast: test_builtin test_codeop test_compile test_compiler_codegen test_dis test_fstring test_future_stmt test_peepholer test_peg_generator test_ssl test_type_comments test_ucn test_unparse
      • calendar: test_calendar test_imaplib test_strftime
      • compileall: test_compileall
      • dis: test__opcode test_compiler_assemble test_dtrace test_monitoring test_patma test_positional_only_arg test_type_cache
      • ensurepip: test_ensurepip test_venv
      • gzip: test_fileinput test_tarfile test_xmlrpc
      • http.server: test_httpservers test_robotparser test_urllib2_localnet
      • inspect: test_abc test_asyncgen test_buffer test_clinic test_grammar test_ntpath test_operator test_posixpath test_pydoc test_signal test_sqlite3 test_traceback test_turtle test_type_annotations test_type_params test_yield_from test_zipimport test_zipimport_support test_zoneinfo
      • mimetypes: test_mimetypes
      • pdb: test_pdb
      • pickle: test_annotationlib test_asyncio test_bool test_bz2 test_concurrent_futures test_configparser test_ctypes test_dict test_enumerate test_importlib test_io test_iter test_list test_lzma test_memoryio test_os test_pathlib test_pickle test_picklebuffer test_pickletools test_random test_range test_shelve test_socket test_str test_string test_time test_trace test_tuple test_type_aliases test_unittest test_xpickle test_zipfile test_zoneinfo
      • platform: test__locale test__osx_support test_asyncio test_baseexception test_cmath test_ctypes test_fcntl test_math test_regrtest test_shutil test_strptime test_winreg test_wsgiref
      • py_compile: test_cmd_line_script test_importlib test_modulefinder test_multiprocessing_main_handling test_py_compile test_runpy
      • random: test_asyncio test_bisect test_complex test_context test_dbm_dumb test_devpoll test_dummy_thread test_email test_float test_grp test_heapq test_hmac test_importlib test_int test_long test_mmap test_numeric_tower test_poll test_pow test_pprint test_pwd test_queue test_richcmp test_selectors test_sort test_strtod test_struct test_sys test_thread test_threading test_tokenize test_zipfile test_zstd
      • sqlite3.main: test_sqlite3
      • tokenize: test_linecache test_tabnanny
      • webbrowser: test_webbrowser
      • zipapp: test_zipapp
      • zipfile: test_pkgutil test_zipfile test_zipfile64
    • collections: test_asyncio test_c_locale_coercion test_call test_contains test_embed test_exception_group test_file test_fileio test_funcattrs test_hash test_iterlen test_json test_pathlib test_reprlib test_sqlite3 test_urllib test_userdict test_userlist test_userstring test_with
      • concurrent.futures._base: test_concurrent_futures
      • dbm.sqlite3: test_dbm_sqlite3
      • difflib: test_difflib test_profile test_sys_settrace
      • idlelib: test_idle
      • importlib.metadata: test_importlib
      • logging: test_asyncio test_hashlib test_support test_urllib2net
      • multiprocessing: test_asyncio test_concurrent_futures
      • pkgutil: test_pyrepl
      • pprint: test_htmlparser test_sys_setprofile
      • queue: test_android test_concurrent_futures test_sched
      • selectors: test_asyncio test_subprocess
      • shlex: test_shlex
      • shutil: test_ctypes test_filecmp test_glob test_largefile test_launcher test_peg_generator test_sax test_string_literals test_tempfile test_unicode_file
      • ssl: test_ftplib test_httplib test_poplib
      • string: test_email test_fnmatch test_importlib test_pyrepl test_secrets test_string
      • threading: test_asyncio test_concurrent_futures test_contextlib test_ctypes test_docxmlrpc test_external_inspection test_fork1 test_gc test_importlib test_ioctl test_pathlib test_pyrepl test_smtplib test_socketserver test_syslog test_termios test_threadedtempfile test_threading_local
      • traceback: test_asyncio test_code_module test_contextlib_async test_dictcomps test_http_cookiejar test_importlib test_listcomps test_pyexpat test_setcomps test_unittest
      • tracemalloc: test_tracemalloc
      • urllib.parse: test_urllibnet test_urlparse
      • wave: test_wave
      • xml.etree.ElementTree: test_doctest
    • dataclasses: test__colorize test_ctypes
      • pstats: test_pstats
    • email.generator: test_email
      • mailbox: test_mailbox
      • smtplib: test_smtpnet
    • gettext: test_gettext test_tools
      • getopt: test_getopt
    • weakref: test_asyncio test_ctypes test_finalization test_scope test_sqlite3 test_unicodedata test_unittest
      • bdb: test_bdb
      • symtable: test_symtable
      • tempfile: test_cmd_line test_cprofile test_faulthandler test_generated_cases test_importlib test_pkg test_pyrepl test_urllib_response test_winconsoleio

[x] lib: cpython/Lib/collections
[ ] lib: cpython/Lib/_collections_abc.py
[x] test: cpython/Lib/test/test_collections.py
[x] test: cpython/Lib/test/test_deque.py (TODO: 1)
[x] test: cpython/Lib/test/test_defaultdict.py
[x] test: cpython/Lib/test/test_ordered_dict.py

dependencies:

  • collections (native: _collections, _weakref, itertools, sys)
    • _collections_abc
    • _collections_abc (native: sys)
    • warnings (native: _contextvars, _thread, _warnings, builtins, sys)
    • copy
    • abc, annotationlib, heapq, keyword, operator, reprlib

dependent tests: (334 tests)

  • collections: test_annotationlib test_array test_asyncio test_bisect test_builtin test_c_locale_coercion test_call test_collections test_configparser test_contains test_context test_copy test_csv test_ctypes test_defaultdict test_deque test_descr test_dict test_dictviews test_embed test_enum test_exception_group test_file test_fileinput test_fileio test_frame test_funcattrs test_functools test_genericalias test_hash test_httpservers test_inspect test_io test_ipaddress test_iter test_iterlen test_json test_logging test_math test_monitoring test_ordered_dict test_pathlib test_patma test_pickle test_plistlib test_pprint test_pydoc test_random test_reprlib test_richcmp test_set test_shelve test_sqlite3 test_statistics test_string test_struct test_sys test_traceback test_tuple test_types test_typing test_unittest test_urllib test_userdict test_userlist test_userstring test_weakref test_weakset test_with
    • ast: test_ast test_codeop test_compile test_compiler_codegen test_dis test_fstring test_future_stmt test_peepholer test_peg_generator test_site test_ssl test_type_comments test_ucn test_unparse
      • annotationlib: test_grammar test_type_annotations test_type_params
      • dbm.dumb: test_dbm_dumb
      • inspect: test_abc test_argparse test_asyncgen test_buffer test_clinic test_code test_coroutines test_decimal test_generators test_ntpath test_operator test_posixpath test_signal test_turtle test_yield_from test_zipimport test_zipimport_support test_zoneinfo
      • pyclbr: test_pyclbr
      • traceback: test_asyncio test_code_module test_contextlib test_contextlib_async test_dictcomps test_exceptions test_http_cookiejar test_importlib test_listcomps test_pyexpat test_setcomps test_socket test_subprocess test_threadedtempfile test_threading test_unittest
    • asyncio: test_asyncio test_concurrent_futures test_external_inspection test_os test_pdb
    • concurrent.futures._base: test_concurrent_futures
    • dbm.sqlite3: test_dbm_sqlite3
    • difflib: test_difflib test_profile test_sys_settrace
    • dis: test__opcode test_compiler_assemble test_dtrace test_opcache test_positional_only_arg test_type_cache
      • bdb: test_bdb
      • modulefinder: test_importlib test_modulefinder
      • trace: test_trace
    • email.feedparser: test_email
    • http.client: test_docxmlrpc test_hashlib test_unicodedata test_urllib2 test_wsgiref test_xmlrpc
      • urllib.request: test_sax test_urllib2_localnet test_urllib2net test_urllibnet
    • idlelib: test_idle
    • importlib.metadata: test_importlib
    • inspect:
      • cmd: test_cmd
      • dataclasses: test__colorize test_ctypes test_regrtest
      • pkgutil: test_pkgutil test_pyrepl test_runpy
      • rlcompleter: test_pyrepl test_rlcompleter
    • logging: test_support
      • hashlib: test_hmac test_smtplib test_tarfile
      • multiprocessing.util: test_compileall test_concurrent_futures
      • venv: test_venv
    • multiprocessing: test_fcntl test_memoryview test_multiprocessing_main_handling test_re
    • platform: test__locale test__osx_support test_baseexception test_cmath test_ctypes test_mimetypes test_platform test_posix test_shutil test_strptime test_sysconfig test_time test_winreg
    • pprint: test_htmlparser test_sys_setprofile
      • pickle: test_bool test_bytes test_bz2 test_codecs test_concurrent_futures test_ctypes test_email test_enumerate test_fractions test_http_cookies test_itertools test_list test_lzma test_memoryio test_minidom test_picklebuffer test_pickletools test_range test_slice test_str test_structseq test_super test_type_aliases test_unittest test_uuid test_xml_dom_minicompat test_xml_etree test_xpickle test_zipfile test_zlib test_zoneinfo
    • queue: test_android test_concurrent_futures test_dummy_thread test_sched
    • selectors: test_selectors
      • socket: test_epoll test_exception_hierarchy test_ftplib test_httplib test_imaplib test_kqueue test_largefile test_mailbox test_mmap test_poplib test_pty test_smtpnet test_socketserver test_stat test_timeout test_urllib_response
      • subprocess: test_atexit test_audit test_cmd_line test_cmd_line_script test_ctypes test_faulthandler test_file_eintr test_gc test_gzip test_json test_launcher test_msvcrt test_osx_env test_peg_generator test_poll test_py_compile test_pyrepl test_quopri test_repl test_script_helper test_select test_tempfile test_unittest test_utf8_mode test_wait3 test_webbrowser test_zipfile
    • shlex: test_shlex
    • shutil: test_filecmp test_glob test_importlib test_string_literals test_unicode_file
      • ctypes.util: test_ctypes
      • ensurepip: test_ensurepip
      • pathlib: test_importlib test_pathlib test_tomllib test_tools test_winapi test_zipapp test_zstd
      • tempfile: test_cprofile test_doctest test_generated_cases test_importlib test_linecache test_pkg test_pstats test_pyrepl test_tabnanny test_termios test_tokenize test_winconsoleio test_zipfile64
      • zipfile: test_zipfile
    • statistics:
      • random: test_complex test_devpoll test_email test_float test_grp test_heapq test_int test_long test_numeric_tower test_pow test_pwd test_queue test_sort test_strtod test_thread
    • string: test_email test_fnmatch test_pyrepl test_secrets test_string
    • threading: test_concurrent_futures test_ctypes test_fork1 test_importlib test_ioctl test_pyrepl test_robotparser test_syslog test_threading_local
      • dummy_threading: test_dummy_threading
      • sysconfig: test_asdl_parser test_tools
    • traceback:
      • timeit: test_timeit
    • tracemalloc: test_tracemalloc
    • urllib.parse: test_urlparse
    • wave: test_wave

Legend:

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant