FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-142956: Add TOML 1.1.0 support by StanFromIreland · Pull Request #143028 · python/cpython · GitHub

Repository navigation

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .json  (4) .py  (2) .rst  (3) .toml  (4) All 4 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
6 changes: 5 additions & 1 deletion Doc/library/tomllib.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

--------------

This module provides an interface for parsing TOML 1.0.0 (Tom's Obvious Minimal
This module provides an interface for parsing TOML 1.1.0 (Tom's Obvious Minimal
Language, `https://toml.io <https://toml.io/en/>`_). This module does not
support writing TOML.

Expand All @@ -31,6 +31,10 @@ support writing TOML.
It is a recommended replacement for this module for editing already
existing TOML files.

.. versionchanged:: next

This module supports TOML 1.1.0.


This module defines the following functions:

Expand Down
11 changes: 10 additions & 1 deletion Doc/whatsnew/3.15.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,7 @@ timeit
:ref:`environment variables <using-on-controlling-color>`.
(Contributed by Yi Hong in :gh:`139374`.)


tkinter
-------

Expand All @@ -765,8 +766,16 @@ tkinter
using Tcl's ``-all`` and ``-overlap`` options.
(Contributed by Rihaan Meher in :gh:`130848`)


tomllib
-------

* Updated to support `TOML 1.1.0
<https://github.com/toml-lang/toml/blob/1.1.0/CHANGELOG.md#110--2025-12-18>`__.


types
------
-----

* Expose the write-through :func:`locals` proxy type
as :data:`types.FrameLocalsProxyType`.
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"local-dt": {"type":"datetime-local","value":"1988-10-27t01:01:01"},
"zulu-dt": {"type":"datetime","value":"1988-10-27t01:01:01z"}
"zulu-dt": {"type":"datetime","value":"1988-10-27t01:01:01z"},
"local-dt-nosec": {"type":"datetime-local","value":"1988-10-27T14:30:00"}
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
local-dt=1988-10-27t01:01:01
zulu-dt=1988-10-27t01:01:01z
local-dt-nosec=1988-10-27T14:30
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
{"t":
{"type":"time-local","value":"00:00:00.999999"}}
{
"t": {"type":"time-local","value":"00:00:00.999999"},
"t2": {"type":"time-local","value":"14:30:00"}
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
t=00:00:00.99999999999999
t=00:00:00.99999999999999
t2=14:30
4 changes: 3 additions & 1 deletion Lib/test/test_tomllib/data/valid/hex-char.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"a": {"type":"string","value":"a"},
"b": {"type":"string","value":"b"},
"c": {"type":"string","value":"c"}
"c": {"type":"string","value":"c"},
"d": {"type":"string","value":"d"},
"esc": {"type":"string","value":"\u001b"}
}
4 changes: 3 additions & 1 deletion Lib/test/test_tomllib/data/valid/hex-char.toml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
a="\u0061"
b="\u0062"
c="\U00000063"
c="\U00000063"
d="\x64"
esc="\e"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
[
{"type":"integer","value":"1"}
]
}
},
"tbl": {"a":{"type":"integer","value":"1"}},
"tbl2": {"b":{"type":"integer","value":"2"}}
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
arr=[1,]
arr=[1,]
tbl={a=1,}
tbl2={
b=2,
}
11 changes: 8 additions & 3 deletions Lib/tomllib/_parser.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"\\n": "\u000A", # linefeed
"\\f": "\u000C", # form feed
"\\r": "\u000D", # carriage return
"\\e": "\u001B", # escape
'\\"': "\u0022", # quote
"\\\\": "\u005C", # backslash
}
Expand Down Expand Up @@ -515,7 +516,7 @@ def parse_inline_table(src: str, pos: Pos, parse_float: ParseFloat) -> tuple[Pos
nested_dict = NestedDict()
flags = Flags()

pos = skip_chars(src, pos, TOML_WS)
pos = skip_comments_and_array_ws(src, pos)
if src.startswith("}", pos):
return pos + 1, nested_dict.dict
while True:
Expand All @@ -530,7 +531,7 @@ def parse_inline_table(src: str, pos: Pos, parse_float: ParseFloat) -> tuple[Pos
if key_stem in nest:
raise TOMLDecodeError(f"Duplicate inline table key {key_stem!r}", src, pos)
nest[key_stem] = value
pos = skip_chars(src, pos, TOML_WS)
pos = skip_comments_and_array_ws(src, pos)
c = src[pos : pos + 1]
if c == "}":
return pos + 1, nested_dict.dict
Expand All @@ -539,7 +540,9 @@ def parse_inline_table(src: str, pos: Pos, parse_float: ParseFloat) -> tuple[Pos
if isinstance(value, (dict, list)):
flags.set(key, Flags.FROZEN, recursive=True)
pos += 1
pos = skip_chars(src, pos, TOML_WS)
pos = skip_comments_and_array_ws(src, pos)
if src.startswith("}", pos):
return pos + 1, nested_dict.dict


def parse_basic_str_escape(
Expand All @@ -565,6 +568,8 @@ def parse_basic_str_escape(
return parse_hex_char(src, pos, 4)
if escape_id == "\\U":
return parse_hex_char(src, pos, 8)
if escape_id == "\\x":
return parse_hex_char(src, pos, 2)
try:
return pos, BASIC_STR_ESCAPE_REPLACEMENTS[escape_id]
except KeyError:
Expand Down
9 changes: 6 additions & 3 deletions Lib/tomllib/_re.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
# E.g.
# - 00:32:00.999999
# - 00:32:00
_TIME_RE_STR = r"([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])(?:\.([0-9]{1,6})[0-9]*)?"
# - 00:32
_TIME_RE_STR = r"([01][0-9]|2[0-3]):([0-5][0-9])(?::([0-5][0-9])(?:\.([0-9]{1,6})[0-9]*)?)?"

RE_NUMBER = re.compile(
r"""
Expand Down Expand Up @@ -74,7 +75,8 @@ def match_to_datetime(match: re.Match[str]) -> datetime | date:
year, month, day = int(year_str), int(month_str), int(day_str)
if hour_str is None:
return date(year, month, day)
hour, minute, sec = int(hour_str), int(minute_str), int(sec_str)
hour, minute = int(hour_str), int(minute_str)
sec = int(sec_str) if sec_str else 0
micros = int(micros_str.ljust(6, "0")) if micros_str else 0
if offset_sign_str:
tz: tzinfo | None = cached_tz(
Expand Down Expand Up @@ -103,8 +105,9 @@ def cached_tz(hour_str: str, minute_str: str, sign_str: str) -> timezone:

def match_to_localtime(match: re.Match[str]) -> time:
hour_str, minute_str, sec_str, micros_str = match.groups()
sec = int(sec_str) if sec_str else 0
micros = int(micros_str.ljust(6, "0")) if micros_str else 0
return time(int(hour_str), int(minute_str), int(sec_str), micros)
return time(int(hour_str), int(minute_str), sec, micros)


def match_to_number(match: re.Match[str], parse_float: ParseFloat) -> Any:
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
:mod:`tomllib`: Updated to support `TOML 1.1.0
<https://github.com/toml-lang/toml/blob/1.1.0/CHANGELOG.md#110--2025-12-18>`_.
Loading

Back | FazBrowse Home | New Git URL