New submission from Марк Коренберг: It will be nice if `int.to_bytes` be able to automatically choose number of bytes to serialize. If so, I could write serialisation code:
def serialize(value: int, signed=True) -> bytes: x = value.to_bytes(-1, 'big', signed=signed) l = value.to_bytes(4, 'big', signed=False) return l + x assert len(serialize(0)) == 4 + 0 # see Issue27623 assert len(serialize(120)) == 4 + 1 assert len(serialize(130)) == 4 + 2 assert len(serialize(130), False) == 4 + 1 ---------- components: Library (Lib) messages: 271488 nosy: mmarkk priority: normal severity: normal status: open title: int.to_bytes(-1, ...) should automatically choose required count of bytes type: enhancement versions: Python 3.6 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue27637> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com