the hashlib package supports variable-length digests SHAKE-128 and SHAKE-256. For those objects, digest() and hexdigest() both need to take a length parameter, without which they fail missing required argument 'length' (pos 1). (other digest algorithms know their own output length and do not require (or accept) an argument to these functions).
However, the typechecker insists that it's wrong to pass that length argument in this case:
0 dkg@bob:~/src/test$ cat hashlib-typing.py
#!/usr/bin/python3
import hashlib
h = hashlib.new("SHAKE-128")
h.update(b'')
print(h.hexdigest(16))
print(h.hexdigest())
0 dkg@bob:~/src/test$ mypy --strict hashlib-typing.py
hashlib-typing.py:6: error: Too many arguments for "hexdigest" of "HASH" [call-arg]
Found 1 error in 1 file (checked 1 source file)
1 dkg@bob:~/src/test$ ./hashlib-typing.py
7f9c2ba4e88f827d616045507605853e
Traceback (most recent call last):
File "/home/dkg/src/test/./hashlib-typing.py", line 7, in <module>
print(h.hexdigest())
~~~~~~~~~~~^^
TypeError: hexdigest() missing required argument 'length' (pos 1)
1 dkg@bob:~/src/test$
the
hashlibpackage supports variable-length digestsSHAKE-128andSHAKE-256. For those objects,digest()andhexdigest()both need to take a length parameter, without which they failmissing required argument 'length' (pos 1). (other digest algorithms know their own output length and do not require (or accept) an argument to these functions).However, the typechecker insists that it's wrong to pass that
lengthargument in this case: