Skip to content

Commit c27daf2

Browse files
committed
Upgrade tomli to 2.3.0
1 parent 23c11ea commit c27daf2

File tree

6 files changed

+39
-31
lines changed

6 files changed

+39
-31
lines changed

news/tomli.vendor.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Upgrade tomli to 2.3.0

src/pip/_vendor/tomli/LICENSE-HEADER

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/pip/_vendor/tomli/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
# Licensed to PSF under a Contributor Agreement.
44

55
__all__ = ("loads", "load", "TOMLDecodeError")
6-
__version__ = "2.2.1" # DO NOT EDIT THIS LINE MANUALLY. LET bump2version UTILITY DO IT
6+
__version__ = "2.3.0" # DO NOT EDIT THIS LINE MANUALLY. LET bump2version UTILITY DO IT
77

88
from ._parser import TOMLDecodeError, load, loads

src/pip/_vendor/tomli/_parser.py

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,8 @@
44

55
from __future__ import annotations
66

7-
from collections.abc import Iterable
8-
import string
97
import sys
108
from types import MappingProxyType
11-
from typing import IO, Any, Final, NamedTuple
12-
import warnings
139

1410
from ._re import (
1511
RE_DATETIME,
@@ -19,7 +15,13 @@
1915
match_to_localtime,
2016
match_to_number,
2117
)
22-
from ._types import Key, ParseFloat, Pos
18+
19+
TYPE_CHECKING = False
20+
if TYPE_CHECKING:
21+
from collections.abc import Iterable
22+
from typing import IO, Any, Final
23+
24+
from ._types import Key, ParseFloat, Pos
2325

2426
# Inline tables/arrays are implemented using recursion. Pathologically
2527
# nested documents cause pure Python to raise RecursionError (which is OK),
@@ -46,19 +48,21 @@
4648

4749
TOML_WS: Final = frozenset(" \t")
4850
TOML_WS_AND_NEWLINE: Final = TOML_WS | frozenset("\n")
49-
BARE_KEY_CHARS: Final = frozenset(string.ascii_letters + string.digits + "-_")
51+
BARE_KEY_CHARS: Final = frozenset(
52+
"abcdefghijklmnopqrstuvwxyz" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "0123456789" "-_"
53+
)
5054
KEY_INITIAL_CHARS: Final = BARE_KEY_CHARS | frozenset("\"'")
51-
HEXDIGIT_CHARS: Final = frozenset(string.hexdigits)
55+
HEXDIGIT_CHARS: Final = frozenset("abcdef" "ABCDEF" "0123456789")
5256

5357
BASIC_STR_ESCAPE_REPLACEMENTS: Final = MappingProxyType(
5458
{
5559
"\\b": "\u0008", # backspace
5660
"\\t": "\u0009", # tab
57-
"\\n": "\u000A", # linefeed
58-
"\\f": "\u000C", # form feed
59-
"\\r": "\u000D", # carriage return
61+
"\\n": "\u000a", # linefeed
62+
"\\f": "\u000c", # form feed
63+
"\\r": "\u000d", # carriage return
6064
'\\"': "\u0022", # quote
61-
"\\\\": "\u005C", # backslash
65+
"\\\\": "\u005c", # backslash
6266
}
6367
)
6468

@@ -92,6 +96,8 @@ def __init__(
9296
or not isinstance(doc, str)
9397
or not isinstance(pos, int)
9498
):
99+
import warnings
100+
95101
warnings.warn(
96102
"Free-form arguments for TOMLDecodeError are deprecated. "
97103
"Please set 'msg' (str), 'doc' (str) and 'pos' (int) arguments only.",
@@ -151,7 +157,7 @@ def loads(__s: str, *, parse_float: ParseFloat = float) -> dict[str, Any]: # no
151157
f"Expected str object, not '{type(__s).__qualname__}'"
152158
) from None
153159
pos = 0
154-
out = Output(NestedDict(), Flags())
160+
out = Output()
155161
header: Key = ()
156162
parse_float = make_safe_parse_float(parse_float)
157163

@@ -220,7 +226,7 @@ class Flags:
220226
EXPLICIT_NEST: Final = 1
221227

222228
def __init__(self) -> None:
223-
self._flags: dict[str, dict] = {}
229+
self._flags: dict[str, dict[Any, Any]] = {}
224230
self._pending_flags: set[tuple[Key, int]] = set()
225231

226232
def add_pending(self, key: Key, flag: int) -> None:
@@ -278,7 +284,7 @@ def get_or_create_nest(
278284
key: Key,
279285
*,
280286
access_lists: bool = True,
281-
) -> dict:
287+
) -> dict[str, Any]:
282288
cont: Any = self.dict
283289
for k in key:
284290
if k not in cont:
@@ -288,7 +294,7 @@ def get_or_create_nest(
288294
cont = cont[-1]
289295
if not isinstance(cont, dict):
290296
raise KeyError("There is no nest behind this key")
291-
return cont
297+
return cont # type: ignore[no-any-return]
292298

293299
def append_nest_to_list(self, key: Key) -> None:
294300
cont = self.get_or_create_nest(key[:-1])
@@ -302,9 +308,10 @@ def append_nest_to_list(self, key: Key) -> None:
302308
cont[last_key] = [{}]
303309

304310

305-
class Output(NamedTuple):
306-
data: NestedDict
307-
flags: Flags
311+
class Output:
312+
def __init__(self) -> None:
313+
self.data = NestedDict()
314+
self.flags = Flags()
308315

309316

310317
def skip_chars(src: str, pos: Pos, chars: Iterable[str]) -> Pos:
@@ -493,9 +500,9 @@ def parse_one_line_basic_str(src: str, pos: Pos) -> tuple[Pos, str]:
493500

494501
def parse_array(
495502
src: str, pos: Pos, parse_float: ParseFloat, nest_lvl: int
496-
) -> tuple[Pos, list]:
503+
) -> tuple[Pos, list[Any]]:
497504
pos += 1
498-
array: list = []
505+
array: list[Any] = []
499506

500507
pos = skip_comments_and_array_ws(src, pos)
501508
if src.startswith("]", pos):
@@ -519,7 +526,7 @@ def parse_array(
519526

520527
def parse_inline_table(
521528
src: str, pos: Pos, parse_float: ParseFloat, nest_lvl: int
522-
) -> tuple[Pos, dict]:
529+
) -> tuple[Pos, dict[str, Any]]:
523530
pos += 1
524531
nested_dict = NestedDict()
525532
flags = Flags()

src/pip/_vendor/tomli/_re.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@
77
from datetime import date, datetime, time, timedelta, timezone, tzinfo
88
from functools import lru_cache
99
import re
10-
from typing import Any, Final
1110

12-
from ._types import ParseFloat
11+
TYPE_CHECKING = False
12+
if TYPE_CHECKING:
13+
from typing import Any, Final
14+
15+
from ._types import ParseFloat
1316

1417
# E.g.
1518
# - 00:32:00.999999
@@ -51,7 +54,7 @@
5154
)
5255

5356

54-
def match_to_datetime(match: re.Match) -> datetime | date:
57+
def match_to_datetime(match: re.Match[str]) -> datetime | date:
5558
"""Convert a `RE_DATETIME` match to `datetime.datetime` or `datetime.date`.
5659
5760
Raises ValueError if the match does not correspond to a valid date
@@ -100,13 +103,13 @@ def cached_tz(hour_str: str, minute_str: str, sign_str: str) -> timezone:
100103
)
101104

102105

103-
def match_to_localtime(match: re.Match) -> time:
106+
def match_to_localtime(match: re.Match[str]) -> time:
104107
hour_str, minute_str, sec_str, micros_str = match.groups()
105108
micros = int(micros_str.ljust(6, "0")) if micros_str else 0
106109
return time(int(hour_str), int(minute_str), int(sec_str), micros)
107110

108111

109-
def match_to_number(match: re.Match, parse_float: ParseFloat) -> Any:
112+
def match_to_number(match: re.Match[str], parse_float: ParseFloat) -> Any:
110113
if match.group("floatpart"):
111114
return parse_float(match.group())
112115
return int(match.group(), 0)

src/pip/_vendor/vendor.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ rich==14.2.0
1313
pygments==2.19.2
1414
resolvelib==1.2.1
1515
setuptools==70.3.0
16-
tomli==2.2.1
16+
tomli==2.3.0
1717
tomli-w==1.2.0
1818
truststore==0.10.4
1919
dependency-groups==1.3.1

0 commit comments

Comments
 (0)