From 2d476d091b69aeb048cc1531daec484140e29a0e Mon Sep 17 00:00:00 2001 From: Shantanu <12621235+hauntsaninja@users.noreply.github.com> Date: Mon, 31 Aug 2020 15:24:45 -0700 Subject: [PATCH] hmac: minor improvements (#4500) --- stdlib/2and3/hmac.pyi | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/stdlib/2and3/hmac.pyi b/stdlib/2and3/hmac.pyi index bac39182b..5b2b705e4 100644 --- a/stdlib/2and3/hmac.pyi +++ b/stdlib/2and3/hmac.pyi @@ -5,8 +5,6 @@ from _typeshed import ReadableBuffer from types import ModuleType from typing import Any, AnyStr, Callable, Optional, Union, overload -_B = Union[bytes, bytearray] - # TODO more precise type for object of hashlib _Hash = Any _DigestMod = Union[str, Callable[[], _Hash], ModuleType] @@ -17,15 +15,15 @@ if sys.version_info >= (3, 8): # In reality digestmod has a default value, but the function always throws an error # if the argument is not given, so we pretend it is a required argument. @overload - def new(key: _B, msg: Optional[ReadableBuffer], digestmod: _DigestMod) -> HMAC: ... + def new(key: bytes, msg: Optional[ReadableBuffer], digestmod: _DigestMod) -> HMAC: ... @overload - def new(key: _B, *, digestmod: _DigestMod) -> HMAC: ... + def new(key: bytes, *, digestmod: _DigestMod) -> HMAC: ... elif sys.version_info >= (3, 4): - def new(key: _B, msg: Optional[ReadableBuffer] = ..., digestmod: Optional[_DigestMod] = ...) -> HMAC: ... + def new(key: bytes, msg: Optional[ReadableBuffer] = ..., digestmod: Optional[_DigestMod] = ...) -> HMAC: ... else: - def new(key: _B, msg: Optional[ReadableBuffer] = ..., digestmod: Optional[_DigestMod] = ...) -> HMAC: ... + def new(key: bytes, msg: Optional[ReadableBuffer] = ..., digestmod: Optional[_DigestMod] = ...) -> HMAC: ... class HMAC: if sys.version_info >= (3,): @@ -33,15 +31,16 @@ class HMAC: if sys.version_info >= (3, 4): block_size: int name: str + def __init__(self, key: bytes, msg: Optional[ReadableBuffer] = ..., digestmod: _DigestMod = ...) -> None: ... def update(self, msg: ReadableBuffer) -> None: ... def digest(self) -> bytes: ... def hexdigest(self) -> str: ... def copy(self) -> HMAC: ... @overload -def compare_digest(a: ReadableBuffer, b: ReadableBuffer) -> bool: ... +def compare_digest(__a: ReadableBuffer, __b: ReadableBuffer) -> bool: ... @overload -def compare_digest(a: AnyStr, b: AnyStr) -> bool: ... +def compare_digest(__a: AnyStr, __b: AnyStr) -> bool: ... if sys.version_info >= (3, 7): - def digest(key: _B, msg: ReadableBuffer, digest: str) -> bytes: ... + def digest(key: bytes, msg: ReadableBuffer, digest: str) -> bytes: ...