This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author rhettinger
Recipients barry, brandtbucher, ethan.furman, mark.dickinson, ncoghlan, petr.viktorin, rhettinger, serhiy.storchaka, veky, vstinner
Date 2021-09-11.00:49:58
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1631321398.55.0.380012644891.issue45155@roundup.psfhosted.org>
In-reply-to
Content
[Mark Dickinson]
> I'd also really like to avoid a system-dependent default.

[Petr Viktorin]
> Exactly, a platform-dependent default is a bad idea.

I concur with Petr and Mark. 

The principal use case for int.to_bytes is to convert an integer of arbitrary size to a binary format for storage or transmission.  The corresponding file load or received data needs to symmetrically restore the int.  The default (whether little or big) needs to be the same on both sides to prevent bugs.  Otherwise, for portable code, we would have to recommend that people not use the default because the output isn't deterministic across systems.

By way of comparison, we've had long standing issues like this in other parts of the language.  For example, this gives inconsistent encodings across systems:

    with open(filename) as f:
        f.write(text)

Not long ago, Inada had to sweep through and add encoding="utf-8" to fix all the bugs caused by the default platform dependent encoding.   Arguably, most code that has ever been written without an explicit encoding is wrong if the files were intended to be shared outside the local file system.

So if Veky wants the default to be "big", that's fine by me.  The important thing is that a *consistent* default be used (not platform dependent).  I won't argue for a "sensible default" because apparently Veky has different sensibilities.
History
Date User Action Args
2021-09-11 00:49:58rhettingersetrecipients: + rhettinger, barry, mark.dickinson, ncoghlan, vstinner, petr.viktorin, ethan.furman, serhiy.storchaka, veky, brandtbucher
2021-09-11 00:49:58rhettingersetmessageid: <1631321398.55.0.380012644891.issue45155@roundup.psfhosted.org>
2021-09-11 00:49:58rhettingerlinkissue45155 messages
2021-09-11 00:49:58rhettingercreate