Author vstinner
Recipients barry, ethan.furman, mark.dickinson, ncoghlan, petr.viktorin, rhettinger, serhiy.storchaka, veky, vstinner
Date 2021-09-10.11:06:54
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1631272014.58.0.175676511772.issue45155@roundup.psfhosted.org>
In-reply-to
Content
I dislike the idea of adding a default length to int.to_bytes(). The length changes the meaning of the output:

>>> (1).to_bytes(2, 'big')
b'\x00\x01'
>>> (1).to_bytes(1, 'big')
b'\x01'

If the intent is to "magically cast an integer to a byte strings", having a fixed length of 1 doesn't help:

>>> (1000).to_bytes(1, "big")
OverflowError: int too big to convert

If the intent is to create a bytes string of length 1, I'm not sure that "re-using" this existing API for that is a good idea.
History
Date User Action Args
2021-09-10 11:06:54vstinnersetrecipients: + vstinner, barry, rhettinger, mark.dickinson, ncoghlan, petr.viktorin, ethan.furman, serhiy.storchaka, veky
2021-09-10 11:06:54vstinnersetmessageid: <1631272014.58.0.175676511772.issue45155@roundup.psfhosted.org>
2021-09-10 11:06:54vstinnerlinkissue45155 messages
2021-09-10 11:06:54vstinnercreate