Skip to content

[3.13] gh-71810: Fix corner case (length==0) for int.to_bytes() (GH-138739) - #138783

Merged
vstinner merged 1 commit into
python:3.13from
miss-islington:backport-011179a-3.13
Sep 11, 2025
Merged

vstinner merged 1 commit into
python:3.13from
miss-islington:backport-011179a-3.13

Conversation

@miss-islington

@miss-islington miss-islington commented Sep 11, 2025 •

Copy link
Copy Markdown
Contributor
>>> (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

(cherry picked from commit 011179a)

Co-authored-by: Sergey B Kirpichev skirpichev@gmail.com
Co-authored-by: Serhiy Storchaka storchaka@gmail.com

…nGH-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
```
(cherry picked from commit 011179a)

Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants