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

Petr Viktorin report at bugs.python.org
Mon Sep 13 05:14:41 EDT 2021


Petr Viktorin <encukou at gmail.com> added the comment:

> I’m not convinced.  I’m more concerned with the obscurity of the API.  If I saw its use in some code I was reviewing, I’d look it up, and then I’d know exactly what it was doing.

I know you would. But there are many others who just try things until they work.

Also, if this does become *the* way to create bytes, it won't be obscure any more -- but you'd still need to remember to always specify byteorder for length > 1. That is, unless you *want* platform-specific behavior, which I don't think is all that often. Even in this case, you want to think about the issue, and omitting the argument is a bad way to encode that you thought about it.


---

Hm, what happened to the idea of only requiring byteorder for `length > 1`? I recall it being discussed

----------

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


More information about the Python-bugs-list mailing list