Title: Make digest_size a class variable
Type: enhancement Stage:
Components: Extension Modules Versions: Python 3.6
Status: open Resolution:
Dependencies: Superseder:
Assigned To: gregory.p.smith Nosy List: christian.heimes, gregory.p.smith, rhettinger
Priority: normal Keywords:

Created on 2016-04-06 07:59 by rhettinger, last changed 2016-09-09 21:05 by gregory.p.smith.

Messages (4)
msg262940 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2016-04-06 07:59
It would be nicer if this worked:

     >>> hashlib.md5.digest_size
msg266761 - (view) Author: Gregory P. Smith (gregory.p.smith) * (Python committer) Date: 2016-05-31 16:52
+cc Christian Heimes: do the upcoming standard hash functions amenable to a constant class attribute digest_size?

Are any of the expected future hashes variable length from a single class / constructor function?
msg266762 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2016-05-31 17:01
Not all hash functions have a fixed digest size, e.g. blake2 is a variable length hash algorithm. How about a new class attribute default_digest_size?
msg275441 - (view) Author: Gregory P. Smith (gregory.p.smith) * (Python committer) Date: 2016-09-09 21:05
I agree that adding a .default_digest_size attribute to the constructors in the hashlib module would be good... the challenge is in actually doing it.  Today they are not classes, they are built-in functions that come from one of two possible extension modules.  Adding properties to a built-in function is a challenge (I don't think that is even possible in the C API, PyMethodDef doesn't support that).

We could hack around it, wrap them in classes, etc.  But they have never been classes and there is little good reason for them to be a type.
Date User Action Args
2016-09-09 21:05:03gregory.p.smithsetmessages: + msg275441
2016-05-31 17:01:22christian.heimessetmessages: + msg266762
2016-05-31 16:52:44gregory.p.smithsetnosy: + christian.heimes
messages: + msg266761
2016-04-06 07:59:10rhettingercreate