From 914e16766cbf6d45c493aa9ef9213f1bd31e2627 Mon Sep 17 00:00:00 2001 From: "Gregory P. Smith" Date: Tue, 15 Oct 2019 09:53:39 -0700 Subject: [PATCH 1/3] hmac digestmod is no longer Optional as of 3.8. --- stdlib/2and3/hmac.pyi | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/stdlib/2and3/hmac.pyi b/stdlib/2and3/hmac.pyi index 47bbc7ec0ec7..108742f96da2 100644 --- a/stdlib/2and3/hmac.pyi +++ b/stdlib/2and3/hmac.pyi @@ -11,7 +11,10 @@ _Hash = Any digest_size: None -if sys.version_info >= (3, 4): +if sys.version_info >= (3, 8): + def new(key: _B, msg: Optional[_B] = ..., + digestmod: Union[str, Callable[[], _Hash], ModuleType] = ...) -> HMAC: ... +elif sys.version_info >= (3, 4): def new(key: _B, msg: Optional[_B] = ..., digestmod: Optional[Union[str, Callable[[], _Hash], ModuleType]] = ...) -> HMAC: ... else: From cd31b5a3ab9d97ab0e40cde2963285f824a039dd Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Wed, 27 May 2020 19:39:16 -0700 Subject: [PATCH 2/3] implement @srittau's suggestion --- stdlib/2and3/hmac.pyi | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/stdlib/2and3/hmac.pyi b/stdlib/2and3/hmac.pyi index 108742f96da2..d773fa877479 100644 --- a/stdlib/2and3/hmac.pyi +++ b/stdlib/2and3/hmac.pyi @@ -1,6 +1,6 @@ # Stubs for hmac -from typing import Any, Callable, Optional, Union, overload, AnyStr +from typing import Any, Callable, Optional, Union, overload, AnyStr, overload from types import ModuleType import sys @@ -12,8 +12,11 @@ _Hash = Any digest_size: None if sys.version_info >= (3, 8): - def new(key: _B, msg: Optional[_B] = ..., - digestmod: Union[str, Callable[[], _Hash], ModuleType] = ...) -> HMAC: ... + _DigestMod = Union[str, Callable[[], _Hash], ModuleType] + @overload + def new(key: _B, msg: Optional[_B], digestmod: _DigestMod) -> HMAC: ... + @overload + def new(key: _B, *, digestmod: _DigestMod) -> HMAC: ... elif sys.version_info >= (3, 4): def new(key: _B, msg: Optional[_B] = ..., digestmod: Optional[Union[str, Callable[[], _Hash], ModuleType]] = ...) -> HMAC: ... From b0bddc63b1d8b39709aa8c2b66ada3f91af1340c Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Wed, 27 May 2020 20:10:21 -0700 Subject: [PATCH 3/3] add to whitelist, add comment --- stdlib/2and3/hmac.pyi | 2 ++ tests/stubtest_whitelists/py38.txt | 1 + tests/stubtest_whitelists/py39.txt | 1 + 3 files changed, 4 insertions(+) diff --git a/stdlib/2and3/hmac.pyi b/stdlib/2and3/hmac.pyi index d773fa877479..fd550e320960 100644 --- a/stdlib/2and3/hmac.pyi +++ b/stdlib/2and3/hmac.pyi @@ -13,6 +13,8 @@ digest_size: None if sys.version_info >= (3, 8): _DigestMod = Union[str, Callable[[], _Hash], ModuleType] + # 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[_B], digestmod: _DigestMod) -> HMAC: ... @overload diff --git a/tests/stubtest_whitelists/py38.txt b/tests/stubtest_whitelists/py38.txt index d264cfbf03f8..806c49ea56c9 100644 --- a/tests/stubtest_whitelists/py38.txt +++ b/tests/stubtest_whitelists/py38.txt @@ -48,6 +48,7 @@ functools.partialmethod.__get__ functools.singledispatchmethod.__call__ # A lie to reflect that the descriptor get returns a callable gettext.install gettext.translation +hmac.new # Stub is a white lie; see comments in the stub http.client.HTTPSConnection.__init__ http.cookiejar.DefaultCookiePolicy.__init__ http.server.SimpleHTTPRequestHandler.__init__ diff --git a/tests/stubtest_whitelists/py39.txt b/tests/stubtest_whitelists/py39.txt index bdbcd06419ba..e18a7e0bc118 100644 --- a/tests/stubtest_whitelists/py39.txt +++ b/tests/stubtest_whitelists/py39.txt @@ -101,6 +101,7 @@ functools.singledispatchmethod.__call__ gettext.install gettext.translation hmac.compare_digest +hmac.new # Stub is a white lie; see comments in the stub http.client.HTTPSConnection.__init__ http.cookiejar.DefaultCookiePolicy.__init__ http.server.SimpleHTTPRequestHandler.__init__