classification
Title: Hashlib/blake2* missing 'data' keyword argument
Type: behavior Stage: patch review
Components: Documentation Versions: Python 3.8, Python 3.7, Python 3.6
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: serhiy.storchaka Nosy List: Juuso Lehtivarjo, christian.heimes, docs@python, serhiy.storchaka, vstinner, xtreak
Priority: normal Keywords: patch

Created on 2018-06-01 08:36 by Juuso Lehtivarjo, last changed 2018-07-31 16:22 by serhiy.storchaka.

Pull Requests
URL Status Linked Edit
PR 8346 merged serhiy.storchaka, 2018-07-20 06:13
PR 8581 merged serhiy.storchaka, 2018-07-31 06:57
Messages (14)
msg318370 - (view) Author: Juuso Lehtivarjo (Juuso Lehtivarjo) Date: 2018-06-01 08:36
In python 3.6.5: hashlib blake2b/blake2s constructors do not recognize 'data' keyword. Try the following:

from hashlib import blake2b
print (blake2b(b"foobar").hexdigest()) # works
print (blake2b(data=b"foobar").hexdigest()) # TypeError: 'data' is an invalid keyword argument for this function
msg321414 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2018-07-11 08:02
None of the hashlib functions are taking keyword arguments for data:

>>> hashlib.sha256(data=b'foo')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: openssl_sha256() takes no keyword arguments
>>> hashlib.blake2b(data=b'foo')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'data' is an invalid keyword argument for this function
msg321455 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2018-07-11 14:19
> None of the hashlib functions are taking keyword arguments for data: ...

So it's just a documentation issue, no?

https://docs.python.org/dev/library/hashlib.html#creating-hash-objects

Juuso Lehtivarjo: do you want to write a pull request to fix the documentation?
msg321945 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python triager) Date: 2018-07-19 10:16
This was introduced as part of https://hg.python.org/cpython/rev/4969f6d343b1 . In addition to the signature there is also a line at https://docs.python.org/dev/library/hashlib.html#simple-hashing which could be removed 

> As a shortcut, you can pass the first chunk of data to update directly to the constructor as the first argument (or as data keyword argument)


Thanks
msg321948 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-07-19 11:09
hashlib.blake2b() and some other constructors accept the first chunk of data as the "string" keyword argument.

>>> hashlib.blake2b(string=b'')
<_blake2.blake2b object at 0x7f2847a9c430>
>>> hashlib.blake2s(string=b'')
<_blake2.blake2s object at 0x7f28468f6290>
>>> hashlib.sha3_224(string=b'')
<_sha3.sha3_224 object at 0x7f28468f6608>
>>> hashlib.sha3_256(string=b'')
<_sha3.sha3_256 object at 0x7f28468f6290>
>>> hashlib.sha3_384(string=b'')
<_sha3.sha3_384 object at 0x7f28468f6608>
>>> hashlib.sha3_512(string=b'')
<_sha3.sha3_512 object at 0x7f28468f6290>
>>> hashlib.shake_128(string=b'')
<_sha3.shake_128 object at 0x7f28468f6608>
>>> hashlib.shake_256(string=b'')
<_sha3.shake_256 object at 0x7f28468f6290>
msg321949 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2018-07-19 11:20
Please treat the first argument as positional-only argument. I don't want to standardize on 'string'.
msg321955 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-07-19 12:05
I take this issue because there are many other issues with handling arguments in the hashlib module.
msg322732 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-07-31 06:50
New changeset f1d36d8efaecd5c84cb35e35119b283f37d83c40 by Serhiy Storchaka in branch 'master':
bpo-33729: Fix issues with arguments parsing in hashlib. (GH-8346)
https://github.com/python/cpython/commit/f1d36d8efaecd5c84cb35e35119b283f37d83c40
msg322738 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-07-31 07:22
New changeset 47957dab94a4efa2fee61c9a8193f78300950769 by Serhiy Storchaka in branch '3.7':
[3.7] bpo-33729: Fix issues with arguments parsing in hashlib. (GH-8346) (GH-8581)
https://github.com/python/cpython/commit/47957dab94a4efa2fee61c9a8193f78300950769
msg322740 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2018-07-31 07:26
Your PR changed way to many aspects of the code in one commit. I also don't like the fact, that you pushed such a big change without waiting for my feedback. For the past two weeks I have been travelling to conferences and had no time to review your PR. There was no need to rush it.
msg322741 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2018-07-31 07:28
The backport to 3.6 and 3.7 are breaking backwards compatibility and compatibility with PEP 247.
msg322744 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-07-31 08:06
Sorry. Do you prefer to revert the whole changes or just some parts?
msg322781 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2018-07-31 14:25
I have no opinion on the change in the master branch, but I agree with Christian that the 3.7 change should be reverted since it breaks the backward compatibility.

Serhiy modified int() in Python 3.7 to convert its first parameter to positional only parameter. IMHO it's ok to do such change. Moreover, the change has been documented in What's New in Python 3.7:
https://docs.python.org/dev/whatsnew/3.7.html#api-and-feature-removals

If you decide to keep the change in the master branch, it should be documented in What's New in Python 3.8, no?
msg322798 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-07-31 16:22
In case of int() the name of it's first argument was documented, in both the module documentation, and in interactive help. But the documented name of the first blake2b() argument was "data", and it never worked. Since help() was not worked for blake2b, the user had weak chance to know that the actual name is "string". Thus there is much less chance of breaking the user code by making this parameter a positional-only than in case of int().

But I think Christian has other concerns.
History
Date User Action Args
2018-09-03 15:21:59serhiy.storchakalinkissue34571 superseder
2018-07-31 16:22:18serhiy.storchakasetmessages: + msg322798
2018-07-31 14:25:07vstinnersetmessages: + msg322781
2018-07-31 08:06:49serhiy.storchakasetmessages: + msg322744
2018-07-31 07:28:55christian.heimessetmessages: + msg322741
2018-07-31 07:26:48christian.heimessetmessages: + msg322740
2018-07-31 07:22:46serhiy.storchakasetmessages: + msg322738
2018-07-31 06:57:46serhiy.storchakasetpull_requests: + pull_request8090
2018-07-31 06:50:19serhiy.storchakasetmessages: + msg322732
2018-07-20 06:13:54serhiy.storchakasetkeywords: + patch
stage: patch review
pull_requests: + pull_request7881
2018-07-19 12:05:02serhiy.storchakasetmessages: + msg321955
2018-07-19 11:34:31serhiy.storchakasetassignee: docs@python -> serhiy.storchaka
2018-07-19 11:20:56christian.heimessetmessages: + msg321949
2018-07-19 11:09:33serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg321948
2018-07-19 10:16:32xtreaksetnosy: + xtreak
messages: + msg321945
2018-07-11 14:19:01vstinnersetnosy: + docs@python, vstinner
messages: + msg321455

assignee: docs@python
components: + Documentation
2018-07-11 08:02:42christian.heimessetmessages: + msg321414
versions: + Python 3.7, Python 3.8
2018-07-11 07:54:46serhiy.storchakasettype: crash -> behavior
2018-06-01 10:50:10ned.deilysetnosy: + christian.heimes
2018-06-01 08:36:11Juuso Lehtivarjocreate