[Python-Dev] Problems with hex-conversion functions

Nick Coghlan ncoghlan at gmail.com
Sun Sep 6 05:51:05 CEST 2009

Brett Cannon wrote:
>> To fix these issues, three changes should be applied:
>> 1. Deprecate bytes.fromhex. This fixes the following problems:
>>    #4 (go with option B and remove the function that does not allow bytes
>> input)
>>    #2 (the binascii functions will be the only way to "do it")
>>    #1 (bytes.hex should not be implemented)
>> 2. In order to keep the functionality that bytes.fromhex has over unhexlify,
>>    the latter function should be able to handle spaces in its input (fix #3)
>> 3. binascii.hexlify should return string as its return type (fix #5)
> Or we fix bytes.fromhex(), add bytes.hex() and deprecate binascii.(un)hexlify().

binascii is the legacy approach here, so if anything was to go, those
functions would be it. I'm not sure getting rid of them is worth the
hassle though (especially in 2.x).

Regarding bytes.hex(), it may be better to modify the builtin hex()
function to accept bytes as an input type.


Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Python-Dev mailing list