From c83d86d2f2001b56a143129df976789cab06a3d0 Mon Sep 17 00:00:00 2001 From: Andrew Aldridge Date: Fri, 15 Sep 2017 10:43:23 -0400 Subject: [PATCH 1/2] Fix blake2 binding Currently calling `hashlib.blake2b` results in the following type errors: Cannot instantiate abstract class '_BlakeHash' with abstract attributes 'copy', 'digest', 'hexdigest' and 'update' Missing positional arguments "data", "key", "salt", "person", "fanout", "depth", "leaf_size", "node_offset", "node_depth", "inner_size", "last_node" in call to "_BlakeHash" --- stdlib/3/hashlib.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/3/hashlib.pyi b/stdlib/3/hashlib.pyi index 64ef70739c9d..695b6357fe5c 100644 --- a/stdlib/3/hashlib.pyi +++ b/stdlib/3/hashlib.pyi @@ -74,5 +74,5 @@ if sys.version_info >= (3, 6): def __init__(self, data: _DataType, digest_size: int = ..., key: _DataType = ..., salt: _DataType = ..., person: _DataType = ..., fanout: int = ..., depth: int = ..., leaf_size: int = ..., node_offset: int = ..., node_depth: int = ..., inner_size: int = ..., last_node: bool = ...) -> None: ... - blake2b = _BlakeHash - blake2s = _BlakeHash + def blake2b(data: _DataType = ..., digest_size: int = ..., key: _DataType = ..., salt: _DataType = ..., person: _DataType = ..., fanout: int = ..., depth: int = ..., leaf_size: int = ..., node_offset: int = ..., node_depth: int = ..., inner_size: int = ..., last_node: bool = ...) -> _BlakeHash: ... + def blake2s(data: _DataType = ..., digest_size: int = ..., key: _DataType = ..., salt: _DataType = ..., person: _DataType = ..., fanout: int = ..., depth: int = ..., leaf_size: int = ..., node_offset: int = ..., node_depth: int = ..., inner_size: int = ..., last_node: bool = ...) -> _BlakeHash: ... From 69b3347d7a67ad798b7c7991e758983d8a8c81ca Mon Sep 17 00:00:00 2001 From: Henri Bai Date: Tue, 10 Oct 2017 15:25:59 -0700 Subject: [PATCH 2/2] Additional changes to reflect the hashlib implementation Modifies the type signatures of: * blake2b * blake2s * sha3_224 * sha3_256 * sha3_384 * sha3_512 * shake_128 * shake_256 To reflect the types that are implemented in the standard library. These should be exposed as `type`s instead of `builtin_function_or_method`s. e.g. In [40]: type(hashlib.blake2b) Out[40]: type In [41]: type(hashlib.md5) Out[41]: builtin_function_or_method --- stdlib/3/hashlib.pyi | 42 ++++++++++++++++++------------------------ 1 file changed, 18 insertions(+), 24 deletions(-) diff --git a/stdlib/3/hashlib.pyi b/stdlib/3/hashlib.pyi index 695b6357fe5c..850205fb7f05 100644 --- a/stdlib/3/hashlib.pyi +++ b/stdlib/3/hashlib.pyi @@ -1,12 +1,11 @@ # Stubs for hashlib import sys -from abc import abstractmethod, ABCMeta from typing import AbstractSet, Optional, Union _DataType = Union[bytes, bytearray, memoryview] -class _Hash(metaclass=ABCMeta): +class _Hash(object): digest_size = ... # type: int block_size = ... # type: int @@ -15,14 +14,12 @@ class _Hash(metaclass=ABCMeta): # formally specified, so may not exist on some platforms name = ... # type: str - @abstractmethod - def update(self, arg: _DataType) -> None: ... - @abstractmethod + def __init__(self, data: _DataType = ...) -> None: ... + + def copy(self) -> _Hash: ... def digest(self) -> bytes: ... - @abstractmethod def hexdigest(self) -> str: ... - @abstractmethod - def copy(self) -> _Hash: ... + def update(self, arg: _DataType) -> None: ... def md5(arg: _DataType = ...) -> _Hash: ... def sha1(arg: _DataType = ...) -> _Hash: ... @@ -42,27 +39,24 @@ if sys.version_info >= (3, 4): def pbkdf2_hmac(hash_name: str, password: _DataType, salt: _DataType, iterations: int, dklen: Optional[int] = ...) -> bytes: ... if sys.version_info >= (3, 6): - class _VarLenHash(metaclass=ABCMeta): + class _VarLenHash(object): digest_size = ... # type: int block_size = ... # type: int name = ... # type: str - @abstractmethod + def __init__(self, data: _DataType = ...) -> None: ... + + def copy(self) -> _VarLenHash: ... def digest(self, length: int) -> bytes: ... - @abstractmethod def hexdigest(self, length: int) -> str: ... - @abstractmethod def update(self, arg: _DataType) -> None: ... - @abstractmethod - def copy(self) -> _VarLenHash: ... - - def sha3_224(arg: _DataType = ...) -> _Hash: ... - def sha3_256(arg: _DataType = ...) -> _Hash: ... - def sha3_384(arg: _DataType = ...) -> _Hash: ... - def sha3_512(arg: _DataType = ...) -> _Hash: ... - def shake_128(arg: _DataType = ...) -> _VarLenHash: ... - def shake_256(arg: _DataType = ...) -> _VarLenHash: ... + sha3_224 = _Hash + sha3_256 = _Hash + sha3_384 = _Hash + sha3_512 = _Hash + shake_128 = _VarLenHash + shake_256 = _VarLenHash def scrypt(password: _DataType, *, salt: _DataType, n: int, r: int, p: int, maxmem: int = ..., dklen: int = ...) -> bytes: ... @@ -72,7 +66,7 @@ if sys.version_info >= (3, 6): PERSON_SIZE = ... # type: int SALT_SIZE = ... # type: int - def __init__(self, data: _DataType, digest_size: int = ..., key: _DataType = ..., salt: _DataType = ..., person: _DataType = ..., fanout: int = ..., depth: int = ..., leaf_size: int = ..., node_offset: int = ..., node_depth: int = ..., inner_size: int = ..., last_node: bool = ...) -> None: ... + def __init__(self, data: _DataType = ..., digest_size: int = ..., key: _DataType = ..., salt: _DataType = ..., person: _DataType = ..., fanout: int = ..., depth: int = ..., leaf_size: int = ..., node_offset: int = ..., node_depth: int = ..., inner_size: int = ..., last_node: bool = ...) -> None: ... - def blake2b(data: _DataType = ..., digest_size: int = ..., key: _DataType = ..., salt: _DataType = ..., person: _DataType = ..., fanout: int = ..., depth: int = ..., leaf_size: int = ..., node_offset: int = ..., node_depth: int = ..., inner_size: int = ..., last_node: bool = ...) -> _BlakeHash: ... - def blake2s(data: _DataType = ..., digest_size: int = ..., key: _DataType = ..., salt: _DataType = ..., person: _DataType = ..., fanout: int = ..., depth: int = ..., leaf_size: int = ..., node_offset: int = ..., node_depth: int = ..., inner_size: int = ..., last_node: bool = ...) -> _BlakeHash: ... + blake2b = _BlakeHash + blake2s = _BlakeHash