|
16 | 16 | import tomli as tomllib |
17 | 17 |
|
18 | 18 | 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 |
20 | 20 | from typing_extensions import TypeAlias as _TypeAlias |
21 | 21 |
|
22 | 22 | from mypy import defaults |
@@ -640,7 +640,7 @@ def parse_mypy_comments( |
640 | 640 | generated. |
641 | 641 | """ |
642 | 642 | errors: list[tuple[int, str]] = [] |
643 | | - sections = {} |
| 643 | + sections: dict[str, object] = {"enable_error_code": [], "disable_error_code": []} |
644 | 644 |
|
645 | 645 | for lineno, line in args: |
646 | 646 | # In order to easily match the behavior for bools, we abuse configparser. |
@@ -681,16 +681,12 @@ def set_strict_flags() -> None: |
681 | 681 | # (the new_sections for an inline config *always* includes 'disable_error_code' and |
682 | 682 | # 'enable_error_code' fields, usually empty, which overwrite the old ones), |
683 | 683 | # 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)) |
694 | 690 | sections.update(new_sections) |
695 | 691 | return sections, errors |
696 | 692 |
|
|
0 commit comments