Skip to content

Commit e14d18b

Browse files
committed
Document tomllib's limits & extensions
1 parent 7f0ccd6 commit e14d18b

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

Doc/library/tomllib.rst

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,48 @@ Conversion Table
157157
+------------------+--------------------------------------------------------------------------------------+
158158
| array of tables | list of dicts |
159159
+------------------+--------------------------------------------------------------------------------------+
160+
161+
Limits and interoperability considerations
162+
------------------------------------------
163+
164+
:mod:`!tomllib` places some limits on the documents it can handle,
165+
and it preserves details that other TOML parsers are allowed to ignore.
166+
When writing portable TOML files, consider only using features that are
167+
guaranteed or recommended by the standard.
168+
169+
The implementation details listed here may change in future versions of Python.
170+
171+
Tables/dicts
172+
Key/value pairs in TOML documents and tables are not guaranteed to be
173+
in any specific order.
174+
175+
.. impl-detail::
176+
:mod:`!tomllib` loads dictionary entries in the order they appear in
177+
the source.
178+
179+
Integers
180+
TOML recommends supporting integers in ``range(−2**63, 2**63)``.
181+
182+
.. impl-detail::
183+
:mod:`!tomllib` uses :ref:`Python's limit on integer string conversion
184+
<int_max_str_digits>` (4300 digits by default).
185+
186+
Floats
187+
TOML recommends supporting at least IEEE 754 binary64 values,
188+
which means that numbers with more than 15 significant decimal digits
189+
are likely to be rounded.
190+
191+
.. impl-detail::
192+
:mod:`!tomllib` uses Python :class:`float` by default;
193+
on many common platforms this is the recommended binary64.
194+
See :data:`sys.float_info` for details.
195+
196+
Nesting limit
197+
TOML 1.1.0 does not recommend a limit on how deeply arrays and tables
198+
may be nested inside one another.
199+
(A limit of 100 has been proposed for a future version of TOML.)
200+
201+
.. impl-detail::
202+
In :mod:`!tomllib`, the nesting level is mainly limited by Python's
203+
:func:`recursion limit <sys.getrecursionlimit>`.
204+
Note that code that calls :mod:`!tomllib` may contribute to the limit.

0 commit comments

Comments
 (0)