[issue45155] Add default arguments for int.to_bytes()

Barry A. Warsaw report at bugs.python.org
Tue Sep 14 01:08:53 EDT 2021


Barry A. Warsaw <barry at python.org> added the comment:

On Sep 13, 2021, at 13:38, STINNER Victor <report at bugs.python.org> wrote:
> It seems like your proposal is mostly guided by: convert an int to a byte (bytes string of length 1). IMO this case is special enough to justify the usage of a different function.

Like bchr() ? <wink>

> What if people expect int.to_bytes() always return a single byte, but then get two bytes by mistake?
> 
> ch = 256
> byte = ch.to_bytes()

The OverflowError you’ll get seems reasonable.

----------

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


More information about the Python-bugs-list mailing list