]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-71810: Fix corner case (length==0) for int.to_bytes() (#138739)
authorSergey B Kirpichev <skirpichev@gmail.com>
Thu, 11 Sep 2025 10:30:53 +0000 (13:30 +0300)
committerGitHub <noreply@github.com>
Thu, 11 Sep 2025 10:30:53 +0000 (12:30 +0200)
commit011179a79a0d7b93ce074b25b0819e96b6dd3315
treee170044fe6d4059708422013eda2d294d044a078
parenta1707e4516c4861efbd43068da6e0db2d38ef87d
gh-71810: Fix corner case (length==0) for int.to_bytes() (#138739)

```pycon
>>> (0).to_bytes(0, 'big', signed=True)
b''
>>> (-1).to_bytes(0, 'big', signed=True)  # was b''
Traceback (most recent call last):
  File "<python-input-0>", line 1, in <module>
    (-1).to_bytes(0, 'big', signed=True)
    ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
OverflowError: int too big to convert
```

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Lib/test/test_long.py
Misc/NEWS.d/next/Core_and_Builtins/2025-09-10-14-53-59.gh-issue-71810.ppf0J-.rst [new file with mode: 0644]
Objects/longobject.c