This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
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
process
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 2022-04-11 14:59 by admin.

Messages (2)
msg373619 - (view) Author: Pavel Trukhanov (Pavel Trukhanov) Date: 2020-07-13 20:26
The documentation found in https://docs.python.org/3/library/hashlib.html#hash-algorithms

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()
b'\x03\x1e\xdd}Ae\x15\x93\xc5\xfe\\\x00o\xa5u+7\xfd\xdf\xf7\xbcN\x84:\xa6\xaf\x0c\x95\x0fK\x94\x06'
>>> m.digest_size
32
>>> m.block_size
64

More condensed:
>>>
hashlib.sha224(b"Nobody inspects the spammish repetition").hexdigest()
'a4337bc45a8fc544c03f52dc550cd6e1e87021bc896588bd79e901e2'
hashlib
```
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.
History
Date User Action Args
2022-04-11 14:59:33adminsetgithub: 85465
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