Skip to content

Align hashlib and HMAC with Python 3.15 - #9170

Merged
youknowone merged 1 commit into
RustPython:mainfrom
youknowdot:fix/hashlib-hmac-315
Oct 17, 2026
Merged

youknowone merged 1 commit into
RustPython:mainfrom
youknowdot:fix/hashlib-hmac-315

Conversation

@youknowdot

Copy link
Copy Markdown
Contributor

Summary

  • Emit the Python 3.15 deprecation warning for the shared native hashlib string= argument, including warning-as-error propagation.
  • Refresh the complete hashlib and HMAC libraries, their canonical tests, and their shared test helper from CPython 3.15.0 (d220409a13b77de7a6c30abe16ea90db01528edc). This includes SHAKE rejection in HMAC fallback paths and consistent unavailable-algorithm behavior.
  • Keep this split to six files. The five Python files are exact canonical copies generated through scripts/update_lib; no new test guards, assertion changes, or unrelated support-suite refresh.

Verification

All local gates passed on the unchanged final source:

  • Full canonical test_hashlib: 88 tests, 15 standard skips; full canonical test_hmac: 146 tests, 46 standard skips. Both ran with -u none; CPU-heavy, bigmem and remote-vector resources were disabled. The normal fast threaded hashing, scrypt, constructor-warning and argument-error cases passed. HMAC's skips also include unavailable _hmac/_sha2 backends.
  • Direct caller regression test_secrets: 11 tests passed.
  • Workspace Rust tests (excluding wasm, venvlauncher and CAPI): 1,359 passed.
  • CAPI tests from crates/capi: 123 passed, 4 existing ignores.
  • Workspace and CAPI doctests, workspace and CAPI Clippy (--all-targets -- -D warnings), and nonthreading VM compilation passed.
  • Normal pre-commit hooks passed. All five Python files still match the pinned canonical source byte-for-byte.

Cargo builds and tests used the locked dependency graph, two jobs, disabled incremental compilation, and serialized execution. The release interpreter was built from this source; native test inventories were checked before execution.

Seven other shared-helper consumers retain compatible decorator calls. Their socket/process suites are outside this focused local run. test_support does not use the hashing helper and remains unchanged, preserving its existing RustPython-specific isolation coverage.

Provenance and assistance

This is an independent split from #8954, based directly on main, without taking unrelated recovery changes.

Pinned upstream files: hashlib.py, hmac.py, test_hashlib.py, test_hmac.py, hashlib_helper.py.

AI-assisted by OpenAI Codex (model version unavailable): source comparison, implementation, canonical migration, local verification, and PR preparation.

Warn on the deprecated shared string keyword and refresh the complete
hashing libraries, canonical suites, and shared helper from CPython
v3.15.0 (d220409a13b77de7a6c30abe16ea90db01528edc) with update_lib.

Keep the six-file family independent and add no RustPython test guards.

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

coderabbitai Bot commented Oct 17, 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: 2f8fb7f6-1f07-464e-87af-d43a9cd46b1c
📥 Commits

Reviewing files that changed from the base of the PR and between 9a16d28 and 45a113b.

⛔ Files ignored due to path filters: 5
  • Lib/hashlib.py is excluded by !Lib/**
  • Lib/hmac.py is excluded by !Lib/**
  • Lib/test/support/hashlib_helper.py is excluded by !Lib/**
  • Lib/test/test_hashlib.py is excluded by !Lib/**
  • Lib/test/test_hmac.py is excluded by !Lib/**
📒 Files selected for processing: 1
  • crates/stdlib/src/hashlib.rs
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Most software today is very much like an Egyptian pyramid with millions of bricks piled on top of each other, with no structural integrity, but just done by brute force and thousands of slaves. - Alan Kay |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  \
   \   (\__/)
       (•ㅅ•)
       /   づ
✨ 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.

@github-actions

Copy link
Copy Markdown
Contributor

📦 Library Dependencies

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

:4: SyntaxWarning: invalid decimal literal
:7: SyntaxWarning: "\z" is an invalid escape sequence. Such sequences will not work in the future. Did you mean "\z"? A raw string is also an option.
:10: SyntaxWarning: "\400" is an invalid octal escape sequence. Such sequences will not work in the future. Did you mean "\400"? A raw string is also an option.
:4: SyntaxWarning: invalid decimal literal
:7: SyntaxWarning: "\z" is an invalid escape sequence. Such sequences will not work in the future. Did you mean "\z"? A raw string is also an option.
:10: SyntaxWarning: "\400" is an invalid octal escape sequence. Such sequences will not work in the future. Did you mean "\400"? A raw string is also an option.
:4: SyntaxWarning: invalid decimal literal
:7: SyntaxWarning: "\z" is an invalid escape sequence. Such sequences will not work in the future. Did you mean "\z"? A raw string is also an option.
:10: SyntaxWarning: "\400" is an invalid octal escape sequence. Such sequences will not work in the future. Did you mean "\400"? A raw string is also an option.
[x] lib: cpython/Lib/hashlib.py
[x] test: cpython/Lib/test/test_hashlib.py

dependencies:

  • hashlib

dependent tests: (147 tests)

  • hashlib: test_hashlib test_hmac test_smtplib test_tarfile test_unicodedata test_urllib2_localnet
    • hmac:
      • imaplib: test_imaplib
      • secrets: test_secrets
      • smtplib: test_smtpnet
    • poplib: test_poplib
    • random: test_asyncio test_bisect test_buffer test_builtin test_bz2 test_collections test_complex test_context test_dbm_dumb test_decimal test_deque test_descr test_devpoll test_dict test_dummy_thread test_email test_float test_functools test_grp test_heapq test_importlib test_int test_io test_itertools test_logging test_long test_lzma test_math test_mmap test_numeric_tower test_ordered_dict test_poll test_posixpath test_pow test_pprint test_pwd test_queue test_random test_regrtest test_richcmp test_selectors test_set test_shutil test_signal test_socket test_sort test_statistics test_strtod test_struct test_sys test_thread test_threading test_tokenize test_traceback test_unparse test_uuid test_weakref test_zipfile test_zlib test_zstd
      • email.generator: test_email
      • email.utils: test_httpservers test_urllib2
      • tempfile: test_argparse test_ast test_asyncio test_bytes test_cmd_line test_compile test_compileall test_concurrent_futures test_contextlib test_cprofile test_csv test_ctypes test_dis test_doctest test_embed test_ensurepip test_faulthandler test_filecmp test_fileinput test_generated_cases test_genericalias test_importlib test_inspect test_launcher test_linecache test_mailbox test_modulefinder test_ntpath test_os test_pathlib test_peg_generator test_pickle test_pkg test_pkgutil test_pstats test_py_compile test_pydoc test_pyrepl test_runpy test_shlex test_site test_string_literals test_subprocess test_support test_sys_settrace test_tabnanny test_tempfile test_termios test_threadedtempfile test_tomllib test_turtle test_urllib test_urllib_response test_venv test_wave test_winconsoleio test_zipapp test_zipfile64 test_zoneinfo
      • uuid: test_os
    • urllib.request: test_http_cookiejar test_sax test_ssl test_urllib2net test_urllibnet
      • pathlib: test_dbm_sqlite3 test_importlib test_json test_netrc test_pathlib test_tomllib test_tools test_winapi test_zipfile

[x] lib: cpython/Lib/hmac.py
[x] test: cpython/Lib/test/test_hmac.py

dependencies:

  • hmac

dependent tests: (9 tests)

  • hmac: test_hmac test_smtplib
    • imaplib: test_imaplib
    • multiprocessing.connection:
      • concurrent.futures.process: test_compileall test_concurrent_futures
    • secrets: test_secrets
    • smtplib: test_smtpnet
      • logging.handlers: test_logging test_pkgutil

Legend:

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

@youknowone
youknowone marked this pull request as ready for review October 17, 2026 02:38
@youknowone
youknowone merged commit 5957092 into RustPython:main Oct 17, 2026
22 checks passed
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 17, 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-17T02:44:51.276992Z 45a113b 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.

@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: 45a113b513

ℹ️ 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_hashlib.py
self.assertRaises(TypeError, get_builtin_constructor, 3)
# ensure that the exception message remains consistent
err = re.escape("new() argument 'name' must be str, not int")
self.assertRaises(TypeError, err, get_builtin_constructor, 3)

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 constructor as the callable under test

When this test runs, assertRaises treats its second argument as the callable, but this changed line passes the regex string err; it therefore catches the resulting 'str' object is not callable TypeError and never executes get_builtin_constructor(3). The test now remains green even if the constructor accepts invalid names, so restore get_builtin_constructor as the second argument.

AGENTS.md reference: AGENTS.md:L276-L282

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