Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7fcfa94

Browse files
[3.7] gh-95778: Mention sys.set_int_max_str_digits() in error message (GH-96874) (GH-96877) (GH-97836)
[3.9] gh-95778: Mention sys.set_int_max_str_digits() in error message (GH-96874) (GH-96877) When ValueError is raised if an integer is larger than the limit, mention sys.set_int_max_str_digits() in the error message. (cherry picked from commit e841ffc) Co-authored-by: Ned Deily <[email protected]> (cherry picked from commit 4118813) Co-authored-by: Victor Stinner <[email protected]>
1 parent 8fc2635 commit 7fcfa94

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

Doc/library/stdtypes.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4774,15 +4774,15 @@ When an operation would exceed the limit, a :exc:`ValueError` is raised:
47744774
>>> _ = int('2' * 5432)
47754775
Traceback (most recent call last):
47764776
...
4777-
ValueError: Exceeds the limit (4300) for integer string conversion: value has 5432 digits.
4777+
ValueError: Exceeds the limit (4300) for integer string conversion: value has 5432 digits; use sys.set_int_max_str_digits() to increase the limit.
47784778
>>> i = int('2' * 4300)
47794779
>>> len(str(i))
47804780
4300
47814781
>>> i_squared = i*i
47824782
>>> len(str(i_squared))
47834783
Traceback (most recent call last):
47844784
...
4785-
ValueError: Exceeds the limit (4300) for integer string conversion: value has 8599 digits.
4785+
ValueError: Exceeds the limit (4300) for integer string conversion: value has 8599 digits; use sys.set_int_max_str_digits() to increase the limit.
47864786
>>> len(hex(i_squared))
47874787
7144
47884788
>>> assert int(hex(i_squared), base=16) == i*i # Hexadecimal is unlimited.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
When :exc:`ValueError` is raised if an integer is larger than the limit,
2+
mention the :func:`sys.set_int_max_str_digits` function in the error message.
3+
Patch by Victor Stinner.

Objects/longobject.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ static PyLongObject small_ints[NSMALLNEGINTS + NSMALLPOSINTS];
4747
Py_ssize_t quick_int_allocs, quick_neg_int_allocs;
4848
#endif
4949

50-
#define _MAX_STR_DIGITS_ERROR_FMT_TO_INT "Exceeds the limit (%d) for integer string conversion: value has %zd digits"
51-
#define _MAX_STR_DIGITS_ERROR_FMT_TO_STR "Exceeds the limit (%d) for integer string conversion"
50+
#define _MAX_STR_DIGITS_ERROR_FMT_TO_INT "Exceeds the limit (%d) for integer string conversion: value has %zd digits; use sys.set_int_max_str_digits() to increase the limit"
51+
#define _MAX_STR_DIGITS_ERROR_FMT_TO_STR "Exceeds the limit (%d) for integer string conversion; use sys.set_int_max_str_digits() to increase the limit"
5252

5353
static PyObject *
5454
get_small_int(sdigit ival)

0 commit comments

Comments
 (0)