From abe94cd2dc68ec03ee78321fe40f3cf934659c7e Mon Sep 17 00:00:00 2001 From: KentaroJay Date: Fri, 4 Jul 2025 12:34:41 +0200 Subject: [PATCH 1/4] gh-136250: Clarify string to integer and integer to string conversion limits in stdtypes documentation --- Doc/library/stdtypes.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index 394c302fd354b96..783bf01feedaa68 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -5946,6 +5946,10 @@ The limit is applied to the number of digit characters in the input or output string when a non-linear conversion algorithm would be involved. Underscores and the sign are not counted towards the limit. +For string to integer conversions, the exact digit count is known and checked. +For integer to string conversions, the limit is applied to an estimated upper +bound of the result size to avoid the expensive conversion operation. + When an operation would exceed the limit, a :exc:`ValueError` is raised: .. doctest:: From a7af606c033d382f0ae0e52dc12415fa06427cef Mon Sep 17 00:00:00 2001 From: Kentaro Jay Takahashi <64148935+KentaroJay@users.noreply.github.com> Date: Fri, 4 Jul 2025 15:46:13 +0200 Subject: [PATCH 2/4] Update stdtypes.rst Co-authored-by: Sergey B Kirpichev --- Doc/library/stdtypes.rst | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index 783bf01feedaa68..4e945f331748c34 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -5946,9 +5946,8 @@ The limit is applied to the number of digit characters in the input or output string when a non-linear conversion algorithm would be involved. Underscores and the sign are not counted towards the limit. -For string to integer conversions, the exact digit count is known and checked. -For integer to string conversions, the limit is applied to an estimated upper -bound of the result size to avoid the expensive conversion operation. +For integer to string conversions, the limit is applied to an estimated +size of the result. When an operation would exceed the limit, a :exc:`ValueError` is raised: From 4abf87b875582ccf019faa1f83304cc41860416e Mon Sep 17 00:00:00 2001 From: KentaroJay Date: Sun, 6 Dec 2026 23:01:00 +0900 Subject: [PATCH 3/4] Reword the note on integer to string conversion limit --- Doc/builtins/stdtypes.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Doc/builtins/stdtypes.rst b/Doc/builtins/stdtypes.rst index 0ead2641b6807cc..b84dafbb7ca90fd 100644 --- a/Doc/builtins/stdtypes.rst +++ b/Doc/builtins/stdtypes.rst @@ -6908,8 +6908,9 @@ The limit is applied to the number of digit characters in the input or output string when a non-linear conversion algorithm would be involved. Underscores and the sign are not counted towards the limit. -For integer to string conversions, the limit is applied to an estimated -size of the result. +For integer to string conversions, the check is based on an estimate of +the lower bound of the result size, so the result may slightly exceed +the limit. When an operation would exceed the limit, a :exc:`ValueError` is raised: From 5800bbaee5b3fceea3df59236a3e336478f01193 Mon Sep 17 00:00:00 2001 From: Stan Ulbrych Date: Sun, 6 Dec 2026 16:55:37 +0000 Subject: [PATCH 4/4] Apply suggestion from @StanFromIreland --- Doc/builtins/stdtypes.rst | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Doc/builtins/stdtypes.rst b/Doc/builtins/stdtypes.rst index b84dafbb7ca90fd..3e9035bd7f0403d 100644 --- a/Doc/builtins/stdtypes.rst +++ b/Doc/builtins/stdtypes.rst @@ -6908,9 +6908,8 @@ The limit is applied to the number of digit characters in the input or output string when a non-linear conversion algorithm would be involved. Underscores and the sign are not counted towards the limit. -For integer to string conversions, the check is based on an estimate of -the lower bound of the result size, so the result may slightly exceed -the limit. +For integer to string conversions, the check is based on a lower bound +of the result size, so the result may slightly exceed the limit. When an operation would exceed the limit, a :exc:`ValueError` is raised: