From 3c3571a8bb08805e8b82e557055c4dd0eba44d85 Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Mon, 6 Feb 2023 05:56:21 +0300 Subject: [PATCH 1/2] Fix typo in the int.to_bytes() docs, now it shows an OverflowError --- Doc/library/stdtypes.rst | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index 0ef03035a572e5..751feb0c8704ee 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -533,8 +533,10 @@ class`. In addition, it provides a few more methods: single byte object. However, when using the default arguments, don't try to convert a value greater than 255 or you'll get an :exc:`OverflowError`:: - >>> (65).to_bytes() - b'A' + >>> (256).to_bytes() + Traceback (most recent call last): + File "", line 1, in + OverflowError: int too big to convert Equivalent to:: From fb579b02f4fbc527115da5d4b09b5664b9d17dc9 Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Sat, 4 Mar 2023 14:09:25 +0300 Subject: [PATCH 2/2] Move around example in to_bytes() to avoid confusion with remark about exception --- Doc/library/stdtypes.rst | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index 2e02c6f58ae8f9..550f808a16dfaa 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -530,13 +530,13 @@ class`. In addition, it provides a few more methods: is ``False``. The default values can be used to conveniently turn an integer into a - single byte object. However, when using the default arguments, don't try - to convert a value greater than 255 or you'll get an :exc:`OverflowError`:: + single byte object:: - >>> (256).to_bytes() - Traceback (most recent call last): - File "", line 1, in - OverflowError: int too big to convert + >>> (65).to_bytes() + b'A' + + However, when using the default arguments, don't try + to convert a value greater than 255 or you'll get an :exc:`OverflowError`. Equivalent to::