[New-bugs-announce] [issue41293] fix confusing example in hashlib docs

Pavel Trukhanov report at bugs.python.org
Mon Jul 13 16:26:50 EDT 2020


New submission from Pavel Trukhanov <pavel.trukhanov at gmail.com>:

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.

----------
assignee: docs at python
components: Documentation
messages: 373619
nosy: Pavel Trukhanov, docs at python
priority: normal
severity: normal
status: open
title: fix confusing example in hashlib docs

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue41293>
_______________________________________


More information about the New-bugs-announce mailing list