[issue34889] int.to_bytes and int.from_bytes should default to the system byte order like the struct module does

Josh Rosenberg report at bugs.python.org
Wed Oct 3 22:39:55 EDT 2018


Josh Rosenberg <shadowranger+python at gmail.com> added the comment:

to_bytes and from_bytes aren't remotely related to native primitive types, struct is. If the associated lengths aren't 2, 4 or 8, there is no real correlation with system level primitives, and providing these defaults makes it easy to accidentally write non-portable code.

Providing a default might make sense, but if you do, it should be a fixed default (so output is portable). Making it depend on the system byte order for no real reason aside from "so I can do struct-like things faster in a non-struct way" is not a valid reason to make a behavior both implicit and inconsistent.

----------
nosy: +josh.r

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


More information about the Python-bugs-list mailing list