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.file_digest() can't handle non-blocking I/O #122179

Closed
Labels
stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error
@srittau

Description

@srittau

Bug report

Bug description:

This came up inpython/typeshed#12414.

The current implementation offile_digest() does not check the return value offileobj.readinto() forNone:

cpython/Lib/hashlib.py

Lines 232 to 236 in2a5d1eb

whileTrue:
size=fileobj.readinto(buf)
ifsize==0:
break# EOF
digestobj.update(view[:size])

While buffered file objects can't returnNone, unbuffered ones can when they are doing non-blocking I/O. Specifically,file_digest()is documented to takeSocketIO objects, which can very much returnNone:

cpython/Lib/socket.py

Lines 694 to 714 in2a5d1eb

defreadinto(self,b):
"""Read up to len(b) bytes into the writable buffer *b* and return
the number of bytes read. If the socket is non-blocking and no bytes
are available, None is returned.
If *b* is non-empty, a 0 return value indicates that the connection
was shutdown at the other end.
"""
self._checkClosed()
self._checkReadable()
ifself._timeout_occurred:
raiseOSError("cannot read from timed out object")
try:
returnself._sock.recv_into(b)
excepttimeout:
self._timeout_occurred=True
raise
excepterrorase:
ife.errnoin_blocking_errnos:
returnNone
raise

CPython versions tested on:

CPython main branch

Operating systems tested on:

Other

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp