implement `tomllib`
Merged
SA
2mo ago+2839+2839+0123456789012345678901234567890123456789-71-71-01234567890123456789
Summary by cubic
Implements the standard-library tomllib module with loads(), load() and TOMLDecodeError, ported from CPython's parser so the accepted grammar, namespace rules, and every error message and position match CPython 3.14.
TOMLDecodeErroris aValueErrorsubclass carrying the same five attributes asjson.JSONDecodeErrorand surfaces through the same payload in the JS and Python hosts; the Python binding rebuilds the attributes on hosts before 3.14 and falls back toValueErrorwhentomllibis absent. The wire sanitizer sizesmsgfrom the exception's message — normally a strict prefix of it — so payloads naming long keys survive the trip, and accepts message-less payloads withmsgcapped at the document limit.- Parsing builds a Rust tree before heap conversion and polls the resource tracker per statement, per array element and per inline-table pair to bound memory use, preflighting array, table, namespace-flag and pending-flag growth like
json.loads; inline tables and arrays nested beyond 100 levels raiseRecursionError, and aposone past the document is accepted for end-of-input escapes. Tree cleanup after aMemoryErroris bounded by depth, and a backslash escape steps over a whole multibyte character, matching CPython's error position. load()reads binary file objects through the same load-then-replay effectcsv.readeruses for unread files; it raisesTypeErrorwhenparse_floatis passed.- Vendors a narrowed typeshed stub, reserves
tomllibin the sandbox module lists, adds dual-run test cases against CPython, and documents the module's divergences in the limitations pages.