Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

hashlib add Protocol for hash-objects #101106

Open
Labels
stdlibPython modules in the Lib dirtopic-typingtype-featureA feature request or enhancement
@randolf-scholz

Description

@randolf-scholz

Feature or enhancement

hashlib describes a Protocol for hash objects without implementing it.
The proposal is simply to create a concreateHash orHashObject protocol that makes it explicit.

Pitch

Using theBuffer Protocol (PEP 688) this should look something like

@runtime_checkableclassHash(Protocol):name:strdefdigest_size(self)->int:"""Return the size of the hash in bytes."""defblock_size(self)->int:"""Return the internal block size of the hash in bytes."""defupdate(self,data:Buffer)->None:"""Update this hash object's state with the provided string."""defdigest(self)->bytes:"""Return the digest value as a string of binary data."""defhexdigest(self)->str:"""Return the digest value as a string of hexadecimal digits."""defcopy(self)->Self:"""Return a copy ("clone") of the hash object."""

Having aProtocol class instead of prose makes it clear how exactly a hash-function needs to look like.

A second suggestion would be to changehashlib.algorithms_guaranteed and hashlib.algorithms_available fromset[str] todict[str, type[Hash]] objects.

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibPython modules in the Lib dirtopic-typingtype-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp