Skip to content

hmac digestmod is no longer Optional as of 3.8.#3367

Merged
srittau merged 5 commits into
python:masterfrom
gpshead:patch-1
May 28, 2020
Merged

hmac digestmod is no longer Optional as of 3.8.#3367
srittau merged 5 commits into
python:masterfrom
gpshead:patch-1

Conversation

@gpshead

@gpshead gpshead commented Oct 15, 2019

Copy link
Copy Markdown
Member

No description provided.

@gpshead

gpshead commented Oct 15, 2019

Copy link
Copy Markdown
Member Author

Is this PR correct? I just did a quick edit via the github UI but I don't have an environment setup to test this in front of me. This is related to python/cpython#16805 :)

The "odd" thing for this is that 3.8.0 shipped with digestmod=None as the default value. and the code accepts and rejects None properly. So Optional[] might still be something type inference would insist on for 3.8.0's code. But None is never a meaningful value to pass so from a caller's point of view having a type checker frown if None is passed would be a good thing.

@srittau srittau left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left my comment below.

Comment thread stdlib/2and3/hmac.pyi Outdated
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: ...

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit of a weird situation, but since you must provide the digestmod argument in 3.8 or you get an exception I don't think it would be correct to say that it has a default value. I'd prefer to see two overloads: One where all three arguments must be given and one similar to def new(key, *, digestmod). This would still allow to leave out msg when digestmod is given as a keyword argument, but requires digestmod in all cases.

@srittau

srittau commented Oct 15, 2019

Copy link
Copy Markdown
Collaborator

Also, this seems to be missing from the release notes.

@JelleZijlstra

Copy link
Copy Markdown
Member

@srittau I implemented your suggestion, could you take a look?

@srittau
srittau merged commit a9d5a1e into python:master May 28, 2020
vishalkuo pushed a commit to vishalkuo/typeshed that referenced this pull request Jun 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants