diff --git a/stdlib/@tests/stubtest_allowlists/common.txt b/stdlib/@tests/stubtest_allowlists/common.txt index 13024e94a..f29461ebc 100644 --- a/stdlib/@tests/stubtest_allowlists/common.txt +++ b/stdlib/@tests/stubtest_allowlists/common.txt @@ -417,8 +417,6 @@ csv.DictWriter.__init__ # runtime sig has *args but will error if more than 5 p dataclasses.field # White lies around defaults email.policy.EmailPolicy.message_factory # "type" at runtime, but protocol in stubs hashlib.scrypt # Raises TypeError if salt, n, r or p are None -hashlib.sha3_\d+ # Can be a class or a built-in function, can't be subclassed at runtime -hashlib.shake_\d+ # Can be a class or a built-in function, can't be subclassed at runtime hmac.HMAC.blocksize # use block_size instead # We can't distinguish not having a default value from having a default value of inspect.Parameter.empty diff --git a/stdlib/@tests/stubtest_allowlists/py38.txt b/stdlib/@tests/stubtest_allowlists/py38.txt index 8a8cebab1..ace9fd787 100644 --- a/stdlib/@tests/stubtest_allowlists/py38.txt +++ b/stdlib/@tests/stubtest_allowlists/py38.txt @@ -262,3 +262,7 @@ email._header_value_parser.SPECIALSNL email.errors.HeaderWriteError email.utils.getaddresses email.utils.parseaddr + +# Weird special builtins that are typed as functions, but aren't functions +hashlib.sha3_\d+ # Class in 3.8, can't be subclassed at runtime, built-in function 3.9+ +hashlib.shake_\d+ # Class in 3.8, can't be subclassed at runtime, built-in function 3.9+ diff --git a/stdlib/hashlib.pyi b/stdlib/hashlib.pyi index 059f0f6e4..74687d9ab 100644 --- a/stdlib/hashlib.pyi +++ b/stdlib/hashlib.pyi @@ -56,12 +56,20 @@ class _Hash: def block_size(self) -> int: ... @property def name(self) -> str: ... - def __init__(self, data: ReadableBuffer = ...) -> None: ... def copy(self) -> Self: ... def digest(self) -> bytes: ... def hexdigest(self) -> str: ... def update(self, data: ReadableBuffer, /) -> None: ... +class _VarLenHash: + digest_size: int + block_size: int + name: str + def copy(self) -> _VarLenHash: ... + def digest(self, length: int, /) -> bytes: ... + def hexdigest(self, length: int, /) -> str: ... + def update(self, data: ReadableBuffer, /) -> None: ... + if sys.version_info >= (3, 9): def new(name: str, data: ReadableBuffer = b"", *, usedforsecurity: bool = ...) -> _Hash: ... def md5(string: ReadableBuffer = b"", *, usedforsecurity: bool = True) -> _Hash: ... @@ -70,6 +78,12 @@ if sys.version_info >= (3, 9): def sha256(string: ReadableBuffer = b"", *, usedforsecurity: bool = True) -> _Hash: ... def sha384(string: ReadableBuffer = b"", *, usedforsecurity: bool = True) -> _Hash: ... def sha512(string: ReadableBuffer = b"", *, usedforsecurity: bool = True) -> _Hash: ... + def sha3_224(string: ReadableBuffer = b"", *, usedforsecurity: bool = True) -> _Hash: ... + def sha3_256(string: ReadableBuffer = b"", *, usedforsecurity: bool = True) -> _Hash: ... + def sha3_384(string: ReadableBuffer = b"", *, usedforsecurity: bool = True) -> _Hash: ... + def sha3_512(string: ReadableBuffer = b"", *, usedforsecurity: bool = True) -> _Hash: ... + def shake_128(string: ReadableBuffer = b"", *, usedforsecurity: bool = True) -> _VarLenHash: ... + def shake_256(string: ReadableBuffer = b"", *, usedforsecurity: bool = True) -> _VarLenHash: ... else: def new(name: str, data: ReadableBuffer = b"") -> _Hash: ... @@ -79,6 +93,12 @@ else: def sha256(string: ReadableBuffer = b"") -> _Hash: ... def sha384(string: ReadableBuffer = b"") -> _Hash: ... def sha512(string: ReadableBuffer = b"") -> _Hash: ... + def sha3_224(string: ReadableBuffer = b"") -> _Hash: ... + def sha3_256(string: ReadableBuffer = b"") -> _Hash: ... + def sha3_384(string: ReadableBuffer = b"") -> _Hash: ... + def sha3_512(string: ReadableBuffer = b"") -> _Hash: ... + def shake_128(string: ReadableBuffer = b"") -> _VarLenHash: ... + def shake_256(string: ReadableBuffer = b"") -> _VarLenHash: ... algorithms_guaranteed: AbstractSet[str] algorithms_available: AbstractSet[str] @@ -86,24 +106,6 @@ algorithms_available: AbstractSet[str] def pbkdf2_hmac( hash_name: str, password: ReadableBuffer, salt: ReadableBuffer, iterations: int, dklen: int | None = None ) -> bytes: ... - -class _VarLenHash: - digest_size: int - block_size: int - name: str - def __init__(self, data: ReadableBuffer = ...) -> None: ... - def copy(self) -> _VarLenHash: ... - def digest(self, length: int, /) -> bytes: ... - def hexdigest(self, length: int, /) -> str: ... - def update(self, data: ReadableBuffer, /) -> None: ... - -sha3_224 = _Hash -sha3_256 = _Hash -sha3_384 = _Hash -sha3_512 = _Hash -shake_128 = _VarLenHash -shake_256 = _VarLenHash - def scrypt( password: ReadableBuffer, *, salt: ReadableBuffer, n: int, r: int, p: int, maxmem: int = 0, dklen: int = 64 ) -> bytes: ...