Skip to content

Commit a9d5a1e

Browse files
authored
hmac digestmod is no longer Optional as of 3.8. (#3367)
1 parent 2f0e3db commit a9d5a1e

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

stdlib/2and3/hmac.pyi

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Stubs for hmac
22

3-
from typing import Any, Callable, Optional, Union, overload, AnyStr
3+
from typing import Any, Callable, Optional, Union, overload, AnyStr, overload
44
from types import ModuleType
55
import sys
66

@@ -11,7 +11,15 @@ _Hash = Any
1111

1212
digest_size: None
1313

14-
if sys.version_info >= (3, 4):
14+
if sys.version_info >= (3, 8):
15+
_DigestMod = Union[str, Callable[[], _Hash], ModuleType]
16+
# In reality digestmod has a default value, but the function always throws an error
17+
# if the argument is not given, so we pretend it is a required argument.
18+
@overload
19+
def new(key: _B, msg: Optional[_B], digestmod: _DigestMod) -> HMAC: ...
20+
@overload
21+
def new(key: _B, *, digestmod: _DigestMod) -> HMAC: ...
22+
elif sys.version_info >= (3, 4):
1523
def new(key: _B, msg: Optional[_B] = ...,
1624
digestmod: Optional[Union[str, Callable[[], _Hash], ModuleType]] = ...) -> HMAC: ...
1725
else:

tests/stubtest_whitelists/py38.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ functools.partialmethod.__get__
4646
functools.singledispatchmethod.__call__ # A lie to reflect that the descriptor get returns a callable
4747
gettext.install
4848
gettext.translation
49+
hmac.new # Stub is a white lie; see comments in the stub
4950
http.client.HTTPSConnection.__init__
5051
http.cookiejar.DefaultCookiePolicy.__init__
5152
http.server.SimpleHTTPRequestHandler.__init__

tests/stubtest_whitelists/py39.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ functools.singledispatchmethod.__call__
9797
gettext.install
9898
gettext.translation
9999
hmac.compare_digest
100+
hmac.new # Stub is a white lie; see comments in the stub
100101
http.client.HTTPSConnection.__init__
101102
http.cookiejar.DefaultCookiePolicy.__init__
102103
http.server.SimpleHTTPRequestHandler.__init__

0 commit comments

Comments
 (0)