Skip to content

Commit f7171c0

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent a386f88 commit f7171c0

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

mypy/config_parser.py

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
else:
1717
import tomli as tomllib
1818

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

2323
from mypy import defaults
@@ -244,18 +244,25 @@ def split_commas(value: str) -> list[str]:
244244
}
245245
)
246246

247-
_TomlValue = Union[str, int, float, bool, datetime.datetime, datetime.date, datetime.time, list['_TomlValue'], dict[str, '_TomlValue']]
247+
_TomlValue = Union[
248+
str,
249+
int,
250+
float,
251+
bool,
252+
datetime.datetime,
253+
datetime.date,
254+
datetime.time,
255+
list["_TomlValue"],
256+
dict[str, "_TomlValue"],
257+
]
248258
_TomlDict = dict[str, _TomlValue]
249-
_TomlDictDict = dict[ str, _TomlDict ]
259+
_TomlDictDict = dict[str, _TomlDict]
250260
_ParserHelper = _TomlDictDict | configparser.RawConfigParser
251261

262+
252263
def _parse_individual_file(
253264
config_file: str, stderr: TextIO | None = None
254-
) -> tuple[
255-
_ParserHelper,
256-
dict[str, _INI_PARSER_CALLABLE],
257-
str
258-
] | None:
265+
) -> tuple[_ParserHelper, dict[str, _INI_PARSER_CALLABLE], str] | None:
259266
try:
260267
if is_toml(config_file):
261268
with open(config_file, "rb") as f:
@@ -267,7 +274,7 @@ def _parse_individual_file(
267274
toml_data: _TomlDict = tomllib.load(f)
268275
# Filter down to just mypy relevant toml keys
269276
toml_data_tool = toml_data.get("tool", {})
270-
if not(isinstance(toml_data_tool, dict)) or "mypy" not in toml_data_tool:
277+
if not (isinstance(toml_data_tool, dict)) or "mypy" not in toml_data_tool:
271278
# Here we might be dealing with a toml that just doesn't talk about mypy,
272279
# in which case we currently just ignore it. (Maybe we should really warn?)
273280
return None
@@ -286,7 +293,12 @@ def _parse_individual_file(
286293
parser.read(config_file)
287294
config_types = ini_config_types
288295

289-
except (FileNotFoundError, tomllib.TOMLDecodeError, configparser.Error, MypyConfigTOMLValueError) as err:
296+
except (
297+
FileNotFoundError,
298+
tomllib.TOMLDecodeError,
299+
configparser.Error,
300+
MypyConfigTOMLValueError,
301+
) as err:
290302
print(f"{config_file}: {err}", file=stderr)
291303
return None
292304

@@ -426,6 +438,7 @@ def is_toml(filename: str) -> bool:
426438
"""Detect if a file "is toml", in the sense that it's named *.toml (case-insensitive)."""
427439
return filename.lower().endswith(".toml")
428440

441+
429442
def destructure_overrides(toml_data: _TomlDictDict) -> _ParserHelper:
430443
"""Take the new [[tool.mypy.overrides]] section array in the pyproject.toml file,
431444
and convert it back to a flatter structure that the existing config_parser can handle.
@@ -514,6 +527,7 @@ def destructure_overrides(toml_data: _TomlDictDict) -> _ParserHelper:
514527
del result["mypy"]["overrides"]
515528
return result
516529

530+
517531
def parse_section(
518532
prefix: str,
519533
template: Options,

0 commit comments

Comments
 (0)