diff --git a/stdlib/2/hashlib.pyi b/stdlib/2/hashlib.pyi index 95f2b82f6..375cc59aa 100644 --- a/stdlib/2/hashlib.pyi +++ b/stdlib/2/hashlib.pyi @@ -1,24 +1,26 @@ # Stubs for hashlib (Python 2) -from typing import Tuple +from typing import Tuple, Union + +_DataType = Union[str, bytearray, buffer, memoryview] class _hash(object): # This is not actually in the module namespace. digest_size = 0 block_size = 0 - def update(self, arg: str) -> None: ... + def update(self, arg: _DataType) -> None: ... def digest(self) -> str: ... def hexdigest(self) -> str: ... def copy(self) -> _hash: ... def new(name: str, data: str = ...) -> _hash: ... -def md5(s: str = ...) -> _hash: ... -def sha1(s: str = ...) -> _hash: ... -def sha224(s: str = ...) -> _hash: ... -def sha256(s: str = ...) -> _hash: ... -def sha384(s: str = ...) -> _hash: ... -def sha512(s: str = ...) -> _hash: ... +def md5(s: _DataType = ...) -> _hash: ... +def sha1(s: _DataType = ...) -> _hash: ... +def sha224(s: _DataType = ...) -> _hash: ... +def sha256(s: _DataType = ...) -> _hash: ... +def sha384(s: _DataType = ...) -> _hash: ... +def sha512(s: _DataType = ...) -> _hash: ... algorithms = ... # type: Tuple[str, ...] algorithms_guaranteed = ... # type: Tuple[str, ...] diff --git a/stdlib/3/hashlib.pyi b/stdlib/3/hashlib.pyi index 4d3709b20..fd47015d5 100644 --- a/stdlib/3/hashlib.pyi +++ b/stdlib/3/hashlib.pyi @@ -1,7 +1,9 @@ # Stubs for hashlib from abc import abstractmethod, ABCMeta -from typing import AbstractSet +from typing import AbstractSet, Union + +_DataType = Union[bytes, bytearray, memoryview] class Hash(metaclass=ABCMeta): digest_size = ... # type: int @@ -13,7 +15,7 @@ class Hash(metaclass=ABCMeta): name = ... # type: str @abstractmethod - def update(self, arg: bytes) -> None: ... + def update(self, arg: _DataType) -> None: ... @abstractmethod def digest(self) -> bytes: ... @abstractmethod @@ -21,20 +23,18 @@ class Hash(metaclass=ABCMeta): @abstractmethod def copy(self) -> 'Hash': ... -def md5(arg: bytes = ...) -> Hash: ... -def sha1(arg: bytes = ...) -> Hash: ... -def sha224(arg: bytes = ...) -> Hash: ... -def sha256(arg: bytes = ...) -> Hash: ... -def sha384(arg: bytes = ...) -> Hash: ... -def sha512(arg: bytes = ...) -> Hash: ... +def md5(arg: _DataType = ...) -> Hash: ... +def sha1(arg: _DataType = ...) -> Hash: ... +def sha224(arg: _DataType = ...) -> Hash: ... +def sha256(arg: _DataType = ...) -> Hash: ... +def sha384(arg: _DataType = ...) -> Hash: ... +def sha512(arg: _DataType = ...) -> Hash: ... -def new(name: str, data: bytes = ...) -> Hash: ... +def new(name: str, data: _DataType = ...) -> Hash: ... # New in version 3.2 algorithms_guaranteed = ... # type: AbstractSet[str] algorithms_available = ... # type: AbstractSet[str] # New in version 3.4 -# TODO The documentation says "password and salt are interpreted as buffers of -# bytes", should we declare something other than bytes here? -def pbkdf2_hmac(name: str, password: bytes, salt: bytes, rounds: int, dklen: int = ...) -> bytes: ... +def pbkdf2_hmac(name: str, password: _DataType, salt: _DataType, rounds: int, dklen: int = ...) -> bytes: ...