mirror of
https://github.com/python/cpython.git
synced 2025-07-07 19:35:27 +00:00
gh-133117: Enable stricter mypy checks for tomllib
(#133206)
This commit is contained in:
parent
1550c30fd5
commit
cb3174113e
3 changed files with 8 additions and 10 deletions
|
@ -214,7 +214,7 @@ class Flags:
|
||||||
EXPLICIT_NEST = 1
|
EXPLICIT_NEST = 1
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
self._flags: dict[str, dict] = {}
|
self._flags: dict[str, dict[Any, Any]] = {}
|
||||||
self._pending_flags: set[tuple[Key, int]] = set()
|
self._pending_flags: set[tuple[Key, int]] = set()
|
||||||
|
|
||||||
def add_pending(self, key: Key, flag: int) -> None:
|
def add_pending(self, key: Key, flag: int) -> None:
|
||||||
|
@ -272,7 +272,7 @@ class NestedDict:
|
||||||
key: Key,
|
key: Key,
|
||||||
*,
|
*,
|
||||||
access_lists: bool = True,
|
access_lists: bool = True,
|
||||||
) -> dict:
|
) -> dict[str, Any]:
|
||||||
cont: Any = self.dict
|
cont: Any = self.dict
|
||||||
for k in key:
|
for k in key:
|
||||||
if k not in cont:
|
if k not in cont:
|
||||||
|
@ -486,9 +486,9 @@ def parse_one_line_basic_str(src: str, pos: Pos) -> tuple[Pos, str]:
|
||||||
return parse_basic_str(src, pos, multiline=False)
|
return parse_basic_str(src, pos, multiline=False)
|
||||||
|
|
||||||
|
|
||||||
def parse_array(src: str, pos: Pos, parse_float: ParseFloat) -> tuple[Pos, list]:
|
def parse_array(src: str, pos: Pos, parse_float: ParseFloat) -> tuple[Pos, list[Any]]:
|
||||||
pos += 1
|
pos += 1
|
||||||
array: list = []
|
array: list[Any] = []
|
||||||
|
|
||||||
pos = skip_comments_and_array_ws(src, pos)
|
pos = skip_comments_and_array_ws(src, pos)
|
||||||
if src.startswith("]", pos):
|
if src.startswith("]", pos):
|
||||||
|
@ -510,7 +510,7 @@ def parse_array(src: str, pos: Pos, parse_float: ParseFloat) -> tuple[Pos, list]
|
||||||
return pos + 1, array
|
return pos + 1, array
|
||||||
|
|
||||||
|
|
||||||
def parse_inline_table(src: str, pos: Pos, parse_float: ParseFloat) -> tuple[Pos, dict]:
|
def parse_inline_table(src: str, pos: Pos, parse_float: ParseFloat) -> tuple[Pos, dict[str, Any]]:
|
||||||
pos += 1
|
pos += 1
|
||||||
nested_dict = NestedDict()
|
nested_dict = NestedDict()
|
||||||
flags = Flags()
|
flags = Flags()
|
||||||
|
|
|
@ -52,7 +52,7 @@ RE_DATETIME = re.compile(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def match_to_datetime(match: re.Match) -> datetime | date:
|
def match_to_datetime(match: re.Match[str]) -> datetime | date:
|
||||||
"""Convert a `RE_DATETIME` match to `datetime.datetime` or `datetime.date`.
|
"""Convert a `RE_DATETIME` match to `datetime.datetime` or `datetime.date`.
|
||||||
|
|
||||||
Raises ValueError if the match does not correspond to a valid date
|
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:
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def match_to_localtime(match: re.Match) -> time:
|
def match_to_localtime(match: re.Match[str]) -> time:
|
||||||
hour_str, minute_str, sec_str, micros_str = match.groups()
|
hour_str, minute_str, sec_str, micros_str = match.groups()
|
||||||
micros = int(micros_str.ljust(6, "0")) if micros_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), int(sec_str), micros)
|
||||||
|
|
||||||
|
|
||||||
def match_to_number(match: re.Match, parse_float: ParseFloat) -> Any:
|
def match_to_number(match: re.Match[str], parse_float: ParseFloat) -> Any:
|
||||||
if match.group("floatpart"):
|
if match.group("floatpart"):
|
||||||
return parse_float(match.group())
|
return parse_float(match.group())
|
||||||
return int(match.group(), 0)
|
return int(match.group(), 0)
|
||||||
|
|
|
@ -15,5 +15,3 @@ strict = True
|
||||||
strict_bytes = True
|
strict_bytes = True
|
||||||
local_partial_types = True
|
local_partial_types = True
|
||||||
warn_unreachable = True
|
warn_unreachable = True
|
||||||
# TODO(@sobolevn): remove this setting and refactor any found problems
|
|
||||||
disallow_any_generics = False
|
|
Loading…
Add table
Add a link
Reference in a new issue