Skip to content

tomllib.loads raises ValueError instead of TOMLDecodeError for an over-long integer #153392

Description

@tonghuaroot

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    pendingThe issue will be closed if no feedback is providedstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions