Skip to content

Deprecate the string parameter of hash constructors - #16931

Merged
srittau merged 2 commits into
python:mainfrom
lvuping:hashlib-string-deprecated
Dec 1, 2026
Merged

srittau merged 2 commits into
python:mainfrom
lvuping:hashlib-string-deprecated

Conversation

@lvuping

@lvuping lvuping commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Since Python 3.15, passing the initial data as string= to hashlib.new(), the OpenSSL-backed constructors such as hashlib.md5(), and blake2b/blake2s emits a DeprecationWarning, and the keyword is slated for removal in 3.19 (docs). This moves string into separate @deprecated overloads on the 3.13+ branch, where data is the alternative, so passing both data and string is now rejected as it is at runtime.

Prepared with Claude Code (Claude Opus 5.5).

Assisted-by: Claude Code (Claude Opus 5.5)
Copilot AI balanced review requested due to automatic review settings December 1, 2026 09:45

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@github-actions

This comment has been minimized.

Assisted-by: Claude Code (Claude Opus 5.5)
@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

apprise (https://github.com/caronc/apprise)
- apprise/persistent_store.py:172: error: Attribute function "hash_engine" with type "def openssl_sha256(data: Buffer = ..., *, usedforsecurity: bool = ..., string: Buffer | None = ...) -> HASH" does not accept self argument  [misc]
+ apprise/persistent_store.py:172: error: Attribute function "hash_engine" with type "def openssl_sha256(data: Buffer = ..., *, usedforsecurity: bool = ...) -> HASH" does not accept self argument  [misc]
- apprise/persistent_store.py:172: error: Function gets multiple values for keyword argument "usedforsecurity"  [misc]
- apprise/persistent_store.py:173: error: Argument 1 has incompatible type "bytes"; expected "bool"  [arg-type]
+ apprise/persistent_store.py:172: error: No overload variant matches argument types "bytes", "bool"  [call-overload]
+ apprise/persistent_store.py:172: note: Possible overload variants:
+ apprise/persistent_store.py:172: note:     def openssl_sha256(data, *, usedforsecurity: bool = ...) -> HASH
+ apprise/persistent_store.py:172: note:     def openssl_sha256(usedforsecurity, *, string: Buffer | None) -> HASH

@srittau srittau left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Normally, our deprecations are Python-version exact (>= 3.15 in this instance), but considering that this only ever worked properly in 3.13 and 3.14, according to the docs, an unconditional deprecation seems fine to me.

@srittau
srittau merged commit 1f80171 into python:main Dec 1, 2026
88 checks passed
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.

3 participants