Skip to content

Commit 000f25f

Browse files
solve the typing problem
1 parent 0253c05 commit 000f25f

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

mypy/config_parser.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import tomli as tomllib
1717

1818
from collections.abc import Mapping, MutableMapping, Sequence
19-
from typing import Any, Callable, Final, TextIO, Union
19+
from typing import Any, Callable, Final, TextIO, TypedDict, Union
2020
from typing_extensions import TypeAlias as _TypeAlias
2121

2222
from mypy import defaults
@@ -640,7 +640,7 @@ def parse_mypy_comments(
640640
generated.
641641
"""
642642
errors: list[tuple[int, str]] = []
643-
sections = {}
643+
sections: dict[str, object] = {"enable_error_code": [], "disable_error_code": []}
644644

645645
for lineno, line in args:
646646
# In order to easily match the behavior for bools, we abuse configparser.
@@ -681,16 +681,12 @@ def set_strict_flags() -> None:
681681
# (the new_sections for an inline config *always* includes 'disable_error_code' and
682682
# 'enable_error_code' fields, usually empty, which overwrite the old ones),
683683
# we have to manipulate them specially.
684-
if "enable_error_code" in new_sections:
685-
assert isinstance(new_sections["enable_error_code"], list)
686-
if "disable_error_code" in new_sections:
687-
assert isinstance(new_sections["disable_error_code"], list)
688-
new_sections["enable_error_code"] = list(
689-
set(new_sections["enable_error_code"] + sections.get("enable_error_code", []))
690-
)
691-
new_sections["disable_error_code"] = list(
692-
set(new_sections["disable_error_code"] + sections.get("disable_error_code", []))
693-
)
684+
assert isinstance(neec:=new_sections.get("enable_error_code", []), list)
685+
assert isinstance(eec:=sections.get("enable_error_code", []), list)
686+
assert isinstance(ndec:=new_sections.get("disable_error_code", []), list)
687+
assert isinstance(dec:=new_sections.get("disable_error_code", []), list)
688+
new_sections["enable_error_code"] = list(set(neec + eec))
689+
new_sections["disable_error_code"] = list(set(ndec + dec))
694690
sections.update(new_sections)
695691
return sections, errors
696692

0 commit comments

Comments
 (0)