Skip to content

Commit 1c9b341

Browse files
committed
Add conversion table to docs
1 parent eafc4e0 commit 1c9b341

File tree

1 file changed

+35
-3
lines changed

1 file changed

+35
-3
lines changed

Doc/library/tomllib.rst

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ This module defines the following functions:
3737
.. function:: load(fp, /, *, parse_float=float)
3838

3939
Read a TOML file. The first argument should be a readable and binary file object.
40-
Return a :class:`dict`.
40+
Return a :class:`dict`. Convert TOML types to Python using this
41+
:ref:`conversion table <toml-to-py-table>`.
4142

4243
*parse_float* will be called with the string of every TOML
4344
float to be decoded. By default, this is equivalent to ``float(num_str)``.
@@ -51,8 +52,9 @@ This module defines the following functions:
5152

5253
.. function:: loads(s, /, *, parse_float=float)
5354

54-
Load TOML from a :class:`str` object. The *parse_float* argument has the
55-
same meaning as in :func:`load`.
55+
Load TOML from a :class:`str` object. Return a :class:`dict`. Convert TOML
56+
types to Python using this :ref:`conversion table <toml-to-py-table>`. The
57+
*parse_float* argument has the same meaning as in :func:`load`.
5658

5759
A :exc:`TOMLDecodeError` will be raised on an invalid TOML document.
5860

@@ -84,3 +86,33 @@ Parsing a TOML string::
8486
"""
8587

8688
data = tomllib.loads(toml_str)
89+
90+
91+
Conversion Table
92+
----------------
93+
94+
.. _toml-to-py-table:
95+
96+
+------------------+--------------------------------------------------------------------------------------+
97+
| TOML | Python |
98+
+==================+======================================================================================+
99+
| table | dict |
100+
+------------------+--------------------------------------------------------------------------------------+
101+
| string | str |
102+
+------------------+--------------------------------------------------------------------------------------+
103+
| integer | int |
104+
+------------------+--------------------------------------------------------------------------------------+
105+
| float | float (configurable with *parse_float*) |
106+
+------------------+--------------------------------------------------------------------------------------+
107+
| boolean | bool |
108+
+------------------+--------------------------------------------------------------------------------------+
109+
| offset date-time | datetime.datetime (``tzinfo`` attribute set to an instance of ``datetime.timezone``) |
110+
+------------------+--------------------------------------------------------------------------------------+
111+
| local date-time | datetime.datetime (``tzinfo`` attribute set to ``None``) |
112+
+------------------+--------------------------------------------------------------------------------------+
113+
| local date | datetime.date |
114+
+------------------+--------------------------------------------------------------------------------------+
115+
| local time | datetime.time |
116+
+------------------+--------------------------------------------------------------------------------------+
117+
| array | list |
118+
+------------------+--------------------------------------------------------------------------------------+

0 commit comments

Comments
 (0)