New submission from Марк Коренберг: As you can see, these conversions are not consistent. What is use case to allow that?
=================== In [22]: (-1).to_bytes(0, 'big', signed=True) Out[22]: b'' In [23]: (0).to_bytes(0, 'big', signed=True) Out[23]: b'' As you can see, two different values serialized to same empty bytes sequence. =================== In [28]: int.from_bytes(b'', 'big', signed=True) Out[28]: 0 In [29]: int.from_bytes(b'', 'big', signed=False) Out[29]: 0 Anyway, -1 can not be deserialized. =================== ---------- messages: 271329 nosy: mmarkk priority: normal severity: normal status: open title: int.to_bytes() and int.from_bytes(): raise ValueError when bytes count is zero _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue27623> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com