Title: fix confusing example in hashlib docs
Type: enhancement Stage:
Components: Documentation Versions: Python 3.10, Python 3.9, Python 3.8, Python 3.7, Python 3.6, Python 3.5
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Pavel Trukhanov, christian.heimes, docs@python, gregory.p.smith
Priority: normal Keywords:

Created on 2020-07-13 20:26 by Pavel Trukhanov, last changed 2020-07-14 06:50 by gregory.p.smith.

Messages (2)
msg373619 - (view) Author: Pavel Trukhanov (Pavel Trukhanov) Date: 2020-07-13 20:26
The documentation found in

give us the following two examples:

For example, to obtain the digest of the byte string b'Nobody inspects the spammish repetition':

>>> import hashlib
>>> m = hashlib.sha256()
>>> m.update(b"Nobody inspects")
>>> m.update(b" the spammish repetition")
>>> m.digest()
>>> m.digest_size
>>> m.block_size

More condensed:
hashlib.sha224(b"Nobody inspects the spammish repetition").hexdigest()
It's confusing because two examples use different algo - sha256 and sha224, respectfully. 

Also the first one gets `.digest()` while the other - `.hexdigest()`, which are incomparable.
msg373626 - (view) Author: Gregory P. Smith (gregory.p.smith) * (Python committer) Date: 2020-07-14 06:50
I probably I wrote these docs (a long time ago).  The examples are being used to demonstrate different uses of the APIs including calling update multiple times, different algorithms, a binary digest and a hex digest.  

They weren't mean to show equivalence, but I agree... the wording could be improved to make what they are doing and why more clear.
Date User Action Args
2020-07-14 06:50:43gregory.p.smithsetmessages: + msg373626
2020-07-14 04:07:26xtreaksetnosy: + gregory.p.smith, christian.heimes
2020-07-13 20:28:16Pavel Trukhanovsettype: enhancement
versions: + Python 3.5, Python 3.6, Python 3.7, Python 3.8, Python 3.9, Python 3.10
2020-07-13 20:26:50Pavel Trukhanovcreate