Skip to content

Commit 0775b1c

Browse files
solve all of the typing problems?!
1 parent 637cb15 commit 0775b1c

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

mypy/config_parser.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import tomli as tomllib
1818

1919
from collections.abc import Mapping, MutableMapping, Sequence
20-
from typing import Any, Callable, Final, TextIO, TypedDict, Union
20+
from typing import Callable, Final, TextIO, TypedDict, Union
2121
from typing_extensions import Never, TypeAlias
2222

2323
from mypy import defaults
@@ -246,8 +246,7 @@ def split_commas(value: str) -> list[str]:
246246

247247
_TomlValue = Union[str, int, float, bool, datetime.datetime, datetime.date, datetime.time, list['_TomlValue'], dict[str, '_TomlValue']]
248248
_TomlDict = dict[str, _TomlValue]
249-
_TomlDictMypy = TypedDict("_TomlDictMypy", {"mypy": _TomlDict})
250-
# Sort of like MutableMapping[str, _CONFIG_VALUE_TYPES], but with more (useless) types in it:
249+
_TomlDictMypy = dict[ str, _TomlDict ]
251250
_ParserHelper = _TomlDictMypy | configparser.RawConfigParser
252251

253252
def _parse_individual_file(
@@ -274,11 +273,12 @@ def _parse_individual_file(
274273
return None
275274
if not isinstance(toml_data_tool["mypy"], dict):
276275
raise MypyConfigTOMLValueError(
277-
"If it exists, tool.mypy value must be a table, aka dict. "
276+
"If it exists, tool.mypy must be a table, aka dict. "
278277
"Please make sure you are using appropriate syntax. "
279278
"https://toml.io/en/v1.0.0#table"
280279
)
281-
toml_data_mypy: _TomlDictMypy = {"mypy": toml_data_tool["mypy"]} #ignore other tools
280+
# Ignore other tools' sections, filtering down to just ours:
281+
toml_data_mypy: _TomlDictMypy = {"mypy": toml_data_tool["mypy"]}
282282
parser = destructure_overrides(toml_data_mypy)
283283
config_types = toml_config_types
284284
else:
@@ -426,7 +426,7 @@ def is_toml(filename: str) -> bool:
426426
"""Detect if a file "is toml", in the sense that it's named *.toml (case-insensitive)."""
427427
return filename.lower().endswith(".toml")
428428

429-
def destructure_overrides(toml_data: _TomlDictMypy) -> _TomlDictMypy:
429+
def destructure_overrides(toml_data: _TomlDictMypy) -> _ParserHelper:
430430
"""Take the new [[tool.mypy.overrides]] section array in the pyproject.toml file,
431431
and convert it back to a flatter structure that the existing config_parser can handle.
432432
@@ -514,13 +514,12 @@ def destructure_overrides(toml_data: _TomlDictMypy) -> _TomlDictMypy:
514514
del result["mypy"]["overrides"]
515515
return result
516516

517-
518517
def parse_section(
519518
prefix: str,
520519
template: Options,
521520
set_strict_flags: Callable[[], None],
522-
section: Mapping[str, Any],
523-
config_types: dict[str, Any],
521+
section: Mapping[str, object],
522+
config_types: Mapping[str, object],
524523
stderr: TextIO = sys.stderr,
525524
) -> tuple[dict[str, object], dict[str, str]]:
526525
"""Parse one section of a config file.
@@ -582,7 +581,7 @@ def parse_section(
582581
else:
583582
continue
584583
ct = type(dv)
585-
v: Any = None
584+
v = None
586585
try:
587586
if ct is bool:
588587
if isinstance(section, dict):
@@ -596,6 +595,7 @@ def parse_section(
596595
print(f"{prefix}Can not invert non-boolean key {options_key}", file=stderr)
597596
continue
598597
try:
598+
# Why does pyright complain that 0 positional arguments are accepted here?
599599
v = ct(section.get(key))
600600
except VersionTypeError as err_version:
601601
print(f"{prefix}{key}: {err_version}", file=stderr)

0 commit comments

Comments
 (0)