Skip to content

Implement Python 3.15 base64 APIs - #9085

Merged
youknowone merged 2 commits into
RustPython:mainfrom
youknowdot:binascii-base64-315
Oct 12, 2026
Merged

youknowone merged 2 commits into
RustPython:mainfrom
youknowdot:binascii-base64-315

Conversation

@youknowdot

Copy link
Copy Markdown
Contributor

Summary

Implement the cohesive base64 encoder/decoder API from CPython 3.15.0 final.

  • Add encoder padded, wrapcol, and alphabet options, including whole-quantum wrapping and arbitrary 64-byte alphabets.
  • Add decoder padded, alphabet, ignorechars, and canonical options, with strictness defaulting according to whether ignorechars was supplied.
  • Preserve padding/error precedence, truth-value conversion order, bytes/buffer argument distinctions, and buffer cleanup order.
  • Retain custom-alphabet tables in hidden, traced per-module state. Use the actual bytes key so subclass hashing/equality, errors and reentry follow the reference. Bind the decoder to its exact owning module and preserve module-subclass callable metadata.
  • Remove the unused third-party base64 dependency and add bounded Python regressions. Existing assertions are unchanged; no Lib/ files are modified.

This is the Rust-stage base64 prerequisite for #9079. Other 3.15 codec API additions remain separate work.

Validation

Base: a10744303f6fb113a6082dde133958ad882d25a4.
Head: 2505ad5f95831e62c821aef1ed14054655e9dc46.

  • Independent source review of final-CPython semantics, module ownership, GC traversal/clear, buffer handling, and the narrow module-subclass metadata change.
  • Common and stdlib Clippy passed with -D warnings; normal commit hooks and whitespace checks passed.
  • Fresh Linux native debug build passed with threading, stdlib, stdio, importlib, host environment and documentation enabled.
  • New base64 regression snippet passed on that native binary and the certified CPython 3.15.0 reference. Coverage includes custom cache callbacks/reentry, acquired-buffer lifetimes/aliasing, saved functions, isolated module-cache cycle collection and metadata.
  • Both selected snippet pytest entries passed under CPython 3.15.0.
  • Thirty-six selected canonical base64 tests passed on both interpreters: twelve unchanged upstream methods across bytes, bytearray and memoryview. Methods and required helpers were extracted without importing the broad canonical module.
  • Native harness imports used the embedded standard-library path. All imported Python dependencies matched this candidate’s Lib/ byte-for-byte: 48/48 for the snippet and 92/92 for the canonical runner. binascii itself was the verified native module.
  • Six bounded Sync email, mock, logging, and console behavior with Python 3.15 #9079 email integration checks passed on both interpreters using its exact final-source contentmanager and encoding-alias candidate modules.

Full local workspace/C-API suites, broad canonical modules, SSL integration and non-Linux runtime validation were not run for this head. Hosted CI must establish the remaining matrix. Keep this PR draft and unmerged pending that validation and maintainer review.

AI assistance

OpenAI Codex implemented, reviewed and validated this change under maintainer direction. The exact model identifier is unavailable in this environment; the commit includes an Assisted-by trailer. This draft does not claim completed human validation.

Follow CPython 3.15.0 final d220409a13b77de7a6c30abe16ea90db01528edc for base64 options, alphabets, padding and canonical decoding. Keep reverse-table caches in traced module-native state and preserve module-bound callable semantics. Add bounded Python regressions without editing Lib.

Assisted-by: OpenAI Codex:model identifier unavailable
@coderabbitai

coderabbitai Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration
  • Configuration used: Repository: RustPython/RustPython/.coderabbit.yml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c95a0346-027c-47bf-9957-52e89902a5f0

📥 Commits

Reviewing files that changed from the base of the PR and between f39da82 and 9d459d2.


⛔ Files ignored due to path filters (2)
  • Cargo.lock is excluded by !**/*.lock
  • Lib/test/test_binascii.py is excluded by !Lib/**

📒 Files selected for processing (7)
  • Cargo.toml
  • crates/common/Cargo.toml
  • crates/common/src/binascii.rs
  • crates/stdlib/src/binascii.rs
  • crates/stdlib/src/binascii/base_n.rs
  • crates/vm/src/builtins/builtin_func.rs
  • crates/vm/src/builtins/module.rs

 _________________________________________________
< Undefined behavior is my favorite horror genre. >
 -------------------------------------------------
  \
   \   \
        \ /\
        ( )
      .( o ).
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@codspeed

codspeed Bot commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 62 untouched benchmarks
⏩ 4 skipped benchmarks1


Comparing youknowdot:binascii-base64-315 (2505ad5) with main (f39da82)

Open in CodSpeed

Footnotes

  1. 4 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

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.

stdlib_binascii.py

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.

rather than adding this test, update Lib/test/test_binascii.py to 3.15

Migrate Lib/test/test_binascii.py unchanged from CPython 3.15.0 final using scripts/update_lib and replace the superseded custom base64 snippet. Implement the base32, Base85, Ascii85 and hex ignorechars APIs required by the canonical suite. Share the existing module-bound original-key alphabet cache across base32/base64/base85 and preserve argument and buffer cleanup semantics. Keep the existing base64 kernels and VM state integration unchanged.

Assisted-by: OpenAI Codex:model identifier unavailable
@github-actions

Copy link
Copy Markdown
Contributor

📦 Library Dependencies

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

[x] test: cpython/Lib/test/test_binascii.py

dependencies:

dependent tests: (95 tests)

  • binascii: test_base64 test_binascii test_codecs test_ctypes test_descr test_hashlib test_hmac test_plistlib test_struct test_zlib
    • base64: test_email test_gettext test_httpservers test_smtplib test_urllib2 test_urllib2_localnet test_xmlrpc test_zoneinfo
      • http.server: test_logging test_robotparser
      • logging.handlers: test_concurrent_futures test_pkgutil
      • secrets: test_secrets
      • smtplib: test_smtpnet
      • ssl: test_asyncio test_ftplib test_httplib test_imaplib test_poplib test_ssl test_urllib test_venv
      • urllib.request: test_http_cookiejar test_pathlib test_pydoc test_sax test_site test_urllib2net test_urllibnet
    • email: test_email test_mailbox test_zipfile
      • importlib.metadata: test_importlib
      • mailbox: test_genericalias
      • pydoc: test_enum
    • http.server:
      • wsgiref.simple_server: test_wsgiref
    • plistlib:
      • platform: test__locale test__osx_support test_asyncio test_baseexception test_builtin test_cmath test_ctypes test_fcntl test_math test_mimetypes test_os test_platform test_posix test_regrtest test_shutil test_socket test_strptime test_sysconfig test_time test_winreg
    • quopri: test_quopri
    • zipfile: test_pdb test_zipapp test_zipfile test_zipfile64 test_zipimport test_zipimport_support
      • shutil: test_argparse test_bz2 test_compileall test_ctypes test_embed test_filecmp test_glob test_importlib test_inspect test_largefile test_launcher test_modulefinder test_peg_generator test_py_compile test_reprlib test_string_literals test_subprocess test_support test_tarfile test_tempfile test_traceback test_unicode_file

Legend:

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

@youknowone
youknowone marked this pull request as ready for review October 12, 2026 07:12
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-12T07:24:54.473734Z 9d459d2 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@youknowone
youknowone merged commit 5f3daa5 into RustPython:main Oct 12, 2026
20 of 21 checks passed

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9d459d2b2d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread Lib/test/test_binascii.py
Comment on lines +159 to +163
def test_base64_bad_padding(self):
# Test malformed padding
def _assertRegexTemplate(assert_regex, data,
non_strict_mode_expected_result, **kwargs):
data = self.type2test(data)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Restore the existing binascii test logic

This replacement rewrites the pre-existing strict-mode test, including its helper behavior and test data, rather than merely marking an unsupported case. Repository policy forbids modifying test assertions, logic, or data, so restore the existing canonical test and keep new behavior coverage outside this file.

AGENTS.md reference: AGENTS.md:L275-L275

Useful? React with 👍 / 👎.

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.

2 participants