Skip to content

Commit cb31741

Browse files
authored
gh-133117: Enable stricter mypy checks for tomllib (#133206)
1 parent 1550c30 commit cb31741

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
@@ -214,7 +214,7 @@ class Flags:
214214
EXPLICIT_NEST = 1
215215

216216
def __init__(self) -> None:
217-
self._flags: dict[str, dict] = {}
217+
self._flags: dict[str, dict[Any, Any]] = {}
218218
self._pending_flags: set[tuple[Key, int]] = set()
219219

220220
def add_pending(self, key: Key, flag: int) -> None:
@@ -272,7 +272,7 @@ def get_or_create_nest(
272272
key: Key,
273273
*,
274274
access_lists: bool = True,
275-
) -> dict:
275+
) -> dict[str, Any]:
276276
cont: Any = self.dict
277277
for k in key:
278278
if k not in cont:
@@ -486,9 +486,9 @@ def parse_one_line_basic_str(src: str, pos: Pos) -> tuple[Pos, str]:
486486
return parse_basic_str(src, pos, multiline=False)
487487

488488

489-
def parse_array(src: str, pos: Pos, parse_float: ParseFloat) -> tuple[Pos, list]:
489+
def parse_array(src: str, pos: Pos, parse_float: ParseFloat) -> tuple[Pos, list[Any]]:
490490
pos += 1
491-
array: list = []
491+
array: list[Any] = []
492492

493493
pos = skip_comments_and_array_ws(src, pos)
494494
if src.startswith("]", pos):
@@ -510,7 +510,7 @@ def parse_array(src: str, pos: Pos, parse_float: ParseFloat) -> tuple[Pos, list]
510510
return pos + 1, array
511511

512512

513-
def parse_inline_table(src: str, pos: Pos, parse_float: ParseFloat) -> tuple[Pos, dict]:
513+
def parse_inline_table(src: str, pos: Pos, parse_float: ParseFloat) -> tuple[Pos, dict[str, Any]]:
514514
pos += 1
515515
nested_dict = NestedDict()
516516
flags = Flags()

Lib/tomllib/_re.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
)
5353

5454

55-
def match_to_datetime(match: re.Match) -> datetime | date:
55+
def match_to_datetime(match: re.Match[str]) -> datetime | date:
5656
"""Convert a `RE_DATETIME` match to `datetime.datetime` or `datetime.date`.
5757
5858
Raises ValueError if the match does not correspond to a valid date
@@ -101,13 +101,13 @@ def cached_tz(hour_str: str, minute_str: str, sign_str: str) -> timezone:
101101
)
102102

103103

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

109109

110-
def match_to_number(match: re.Match, parse_float: ParseFloat) -> Any:
110+
def match_to_number(match: re.Match[str], parse_float: ParseFloat) -> Any:
111111
if match.group("floatpart"):
112112
return parse_float(match.group())
113113
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)