Skip to content

Commit 845f4dd

Browse files
authored
[hashlib] Preserve callable factory return types in file_digest (#16508)
1 parent ba787f6 commit 845f4dd

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

‎stdlib/hashlib.pyi‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ from _hashlib import (
2424
)
2525
from _typeshed import ReadableBuffer
2626
from collections.abc import Callable, Set as AbstractSet
27-
from typing import Protocol, overload, type_check_only
27+
from typing import Protocol, TypeVar, overload, type_check_only
28+
29+
_HashT = TypeVar("_HashT", bound=_HashObject)
2830

2931
if sys.version_info >= (3, 15):
3032
__all__ = (
@@ -113,9 +115,12 @@ if sys.version_info >= (3, 11):
113115
def readinto(self, buf: bytearray, /) -> int: ...
114116
def readable(self) -> bool: ...
115117

118+
@overload
119+
def file_digest(fileobj: _BytesIOLike | _FileDigestFileObj, digest: str, /, *, _bufsize: int = 262144) -> HASH: ...
120+
@overload
116121
def file_digest(
117-
fileobj: _BytesIOLike | _FileDigestFileObj, digest: str | Callable[[], _HashObject], /, *, _bufsize: int = 262144
118-
) -> HASH: ...
122+
fileobj: _BytesIOLike | _FileDigestFileObj, digest: Callable[[], _HashT], /, *, _bufsize: int = 262144
123+
) -> _HashT: ...
119124

120125
# Legacy typing-only alias
121126
_Hash = HASH

0 commit comments

Comments
 (0)