Author rhettinger
Recipients christian.heimes, gregory.p.smith, mbussonn, miss-islington, rhettinger
Date 2019-10-15.15:20:03
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
The docs still make it look like *digestmod* is an optional argument:

The help output does as well:

    >>> help(
    Help on function new in module hmac:

    new(key, msg=None, digestmod=None)
        Create a new hashing object and return it.
        key: The starting key for the hash.
        msg: if available, will immediately be hashed into the object's starting
        You can now feed arbitrary strings into the object using its update()
        method, and can ask for the hash value at any time by calling its digest()

Also, it is well outside the Python norms to have a required argument default to None and having that default value be invalid.

Presumably, the type annotation for this would be, "digestmod: Optional[str]=None".  That would further add to the confusion with a required Optional argument.

Another thought:  The usual exception for a missing argument is a TypeError, not a ValueError

Lastly, I'm curious why another algorithm wasn't used (perhaps sha256) as a default rather than removing the default altogether.  This doesn't seems like good API design.

FWIW, this removal broke the third-party package, Bottle:

    Bottle v0.12.17 server starting up (using WSGIRefServer())...
    Listening on http://localhost:8081/
    Hit Ctrl-C to quit. - - [15/Oct/2019 07:53:10] "GET / HTTP/1.1" 200 1471
    Traceback (most recent call last):
      File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/", line 862, in _handle
      File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/", line 1742, in wrapper
        rv = callback(*a, **ka)
      File "", line 32, in check_credentials
        response.set_cookie('token', token, max_age=3600, secret=secret)
      File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/", line 1626, in set_cookie
        value = touni(cookie_encode((name, value), secret))
      File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/", line 2600, in cookie_encode
        sig = base64.b64encode(, msg).digest())
      File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/", line 146, in new
        return HMAC(key, msg, digestmod)
      File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/", line 49, in __init__
        raise ValueError('`digestmod` is required.')
    ValueError: `digestmod` is required.
Date User Action Args
2019-10-15 15:20:04rhettingersetrecipients: + rhettinger, gregory.p.smith, christian.heimes, mbussonn, miss-islington
2019-10-15 15:20:04rhettingersetmessageid: <>
2019-10-15 15:20:04rhettingerlinkissue33604 messages
2019-10-15 15:20:03rhettingercreate