Bug report
Bug description:
tomllib.loads() raises a bare ValueError instead of tomllib.TOMLDecodeError when a document contains an integer with more digits than the interpreter's integer string conversion limit (default 4300, see sys.set_int_max_str_digits).
import tomllib
tomllib.loads("x = " + "9" * 4301)
Actual:
ValueError: Exceeds the limit (4300 digits) for integer string conversion; use sys.set_int_max_str_digits() to increase the limit
Expected: tomllib.TOMLDecodeError. The documentation states that "A TOMLDecodeError will be raised on an invalid TOML document", so a value that cannot be decoded should surface as TOMLDecodeError, not a raw ValueError.
Root cause: in Lib/tomllib/_parser.py, the number branch calls match_to_number(...) without wrapping ValueError, while the sibling date and time branch already wraps match_to_datetime's ValueError into TOMLDecodeError. Negative integers are affected too; hexadecimal, octal, and binary literals are not affected, because they bypass the integer string conversion limit.
Tested on 3.13, 3.14, and main.
CPython versions tested on:
3.13, 3.14, CPython main branch
Operating systems tested on:
No response
Linked PRs
Bug report
Bug description:
tomllib.loads()raises a bareValueErrorinstead oftomllib.TOMLDecodeErrorwhen a document contains an integer with more digits than the interpreter's integer string conversion limit (default 4300, seesys.set_int_max_str_digits).Actual:
Expected:
tomllib.TOMLDecodeError. The documentation states that "ATOMLDecodeErrorwill be raised on an invalid TOML document", so a value that cannot be decoded should surface asTOMLDecodeError, not a rawValueError.Root cause: in
Lib/tomllib/_parser.py, the number branch callsmatch_to_number(...)without wrappingValueError, while the sibling date and time branch already wrapsmatch_to_datetime'sValueErrorintoTOMLDecodeError. Negative integers are affected too; hexadecimal, octal, and binary literals are not affected, because they bypass the integer string conversion limit.Tested on 3.13, 3.14, and main.
CPython versions tested on:
3.13, 3.14, CPython main branch
Operating systems tested on:
No response
Linked PRs