Skip to content

Commit 8525223

Browse files
[3.13] gh-133117: Enable stricter mypy checks for tomllib (GH-133206) (#133343)
gh-133117: Enable stricter mypy checks for `tomllib` (GH-133206) (cherry picked from commit cb31741) Co-authored-by: sobolevn <[email protected]>
1 parent 130491f commit 8525223

File tree

3 files changed

+8
-10
lines changed

3 files changed

+8
-10
lines changed

Lib/tomllib/_parser.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ class Flags:
142142
EXPLICIT_NEST = 1
143143

144144
def __init__(self) -> None:
145-
self._flags: dict[str, dict] = {}
145+
self._flags: dict[str, dict[Any, Any]] = {}
146146
self._pending_flags: set[tuple[Key, int]] = set()
147147

148148
def add_pending(self, key: Key, flag: int) -> None:
@@ -200,7 +200,7 @@ def get_or_create_nest(
200200
key: Key,
201201
*,
202202
access_lists: bool = True,
203-
) -> dict:
203+
) -> dict[str, Any]:
204204
cont: Any = self.dict
205205
for k in key:
206206
if k not in cont:
@@ -409,9 +409,9 @@ def parse_one_line_basic_str(src: str, pos: Pos) -> tuple[Pos, str]:
409409
return parse_basic_str(src, pos, multiline=False)
410410

411411

412-
def parse_array(src: str, pos: Pos, parse_float: ParseFloat) -> tuple[Pos, list]:
412+
def parse_array(src: str, pos: Pos, parse_float: ParseFloat) -> tuple[Pos, list[Any]]:
413413
pos += 1
414-
array: list = []
414+
array: list[Any] = []
415415

416416
pos = skip_comments_and_array_ws(src, pos)
417417
if src.startswith("]", pos):
@@ -433,7 +433,7 @@ def parse_array(src: str, pos: Pos, parse_float: ParseFloat) -> tuple[Pos, list]
433433
return pos + 1, array
434434

435435

436-
def parse_inline_table(src: str, pos: Pos, parse_float: ParseFloat) -> tuple[Pos, dict]:
436+
def parse_inline_table(src: str, pos: Pos, parse_float: ParseFloat) -> tuple[Pos, dict[str, Any]]:
437437
pos += 1
438438
nested_dict = NestedDict()
439439
flags = Flags()

Lib/tomllib/_re.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
)
5050

5151

52-
def match_to_datetime(match: re.Match) -> datetime | date:
52+
def match_to_datetime(match: re.Match[str]) -> datetime | date:
5353
"""Convert a `RE_DATETIME` match to `datetime.datetime` or `datetime.date`.
5454
5555
Raises ValueError if the match does not correspond to a valid date
@@ -95,13 +95,13 @@ def cached_tz(hour_str: str, minute_str: str, sign_str: str) -> timezone:
9595
)
9696

9797

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

103103

104-
def match_to_number(match: re.Match, parse_float: ParseFloat) -> Any:
104+
def match_to_number(match: re.Match[str], parse_float: ParseFloat) -> Any:
105105
if match.group("floatpart"):
106106
return parse_float(match.group())
107107
return int(match.group(), 0)

Lib/tomllib/mypy.ini

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,3 @@ strict = True
1515
strict_bytes = True
1616
local_partial_types = True
1717
warn_unreachable = True
18-
# TODO(@sobolevn): remove this setting and refactor any found problems
19-
disallow_any_generics = False

0 commit comments

Comments
 (0)