mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Cleanup mypy ignore list feature (#88451)
This commit is contained in:
parent
08cdb0e3ee
commit
0d832c0a5a
@ -12,12 +12,6 @@ from homeassistant.const import REQUIRED_PYTHON_VER
|
|||||||
|
|
||||||
from .model import Config, Integration
|
from .model import Config, Integration
|
||||||
|
|
||||||
# Modules which have type hints which known to be broken.
|
|
||||||
# If you are an author of component listed here, please fix these errors and
|
|
||||||
# remove your component from this list to enable type checks.
|
|
||||||
# Do your best to not add anything new here.
|
|
||||||
IGNORED_MODULES: Final[list[str]] = []
|
|
||||||
|
|
||||||
# Component modules which should set no_implicit_reexport = true.
|
# Component modules which should set no_implicit_reexport = true.
|
||||||
NO_IMPLICIT_REEXPORT_MODULES: set[str] = {
|
NO_IMPLICIT_REEXPORT_MODULES: set[str] = {
|
||||||
"homeassistant.components",
|
"homeassistant.components",
|
||||||
@ -98,19 +92,6 @@ PLUGIN_CONFIG: Final[dict[str, dict[str, str]]] = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def _strict_module_in_ignore_list(
|
|
||||||
module: str, ignored_modules_set: set[str]
|
|
||||||
) -> str | None:
|
|
||||||
if module in ignored_modules_set:
|
|
||||||
return module
|
|
||||||
if module.endswith("*"):
|
|
||||||
module = module[:-1]
|
|
||||||
for ignored_module in ignored_modules_set:
|
|
||||||
if ignored_module.startswith(module):
|
|
||||||
return ignored_module
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
def _sort_within_sections(line_iter: Iterable[str]) -> Iterable[str]:
|
def _sort_within_sections(line_iter: Iterable[str]) -> Iterable[str]:
|
||||||
"""Sort lines within sections.
|
"""Sort lines within sections.
|
||||||
|
|
||||||
@ -145,7 +126,7 @@ def _generate_and_validate_strict_typing(config: Config) -> str:
|
|||||||
return "\n".join(_sort_within_sections(lines)) + "\n"
|
return "\n".join(_sort_within_sections(lines)) + "\n"
|
||||||
|
|
||||||
|
|
||||||
def _generate_and_validate_mypy_config(config: Config) -> str: # noqa: C901
|
def _generate_and_validate_mypy_config(config: Config) -> str:
|
||||||
"""Validate and generate mypy config."""
|
"""Validate and generate mypy config."""
|
||||||
|
|
||||||
# Filter empty and commented lines.
|
# Filter empty and commented lines.
|
||||||
@ -163,27 +144,9 @@ def _generate_and_validate_mypy_config(config: Config) -> str: # noqa: C901
|
|||||||
else:
|
else:
|
||||||
strict_core_modules.append(module)
|
strict_core_modules.append(module)
|
||||||
|
|
||||||
ignored_modules_set: set[str] = set(IGNORED_MODULES)
|
|
||||||
for module in strict_modules:
|
|
||||||
if (
|
|
||||||
not module.startswith("homeassistant.components.")
|
|
||||||
and module != "homeassistant.components"
|
|
||||||
):
|
|
||||||
config.add_error(
|
|
||||||
"mypy_config", f"Only components should be added: {module}"
|
|
||||||
)
|
|
||||||
if ignored_module := _strict_module_in_ignore_list(module, ignored_modules_set):
|
|
||||||
config.add_error(
|
|
||||||
"mypy_config",
|
|
||||||
f"Module '{ignored_module}' is in ignored list in mypy_config.py",
|
|
||||||
)
|
|
||||||
|
|
||||||
# Validate that all modules exist.
|
# Validate that all modules exist.
|
||||||
all_modules = (
|
all_modules = (
|
||||||
strict_modules
|
strict_modules + strict_core_modules + list(NO_IMPLICIT_REEXPORT_MODULES)
|
||||||
+ strict_core_modules
|
|
||||||
+ IGNORED_MODULES
|
|
||||||
+ list(NO_IMPLICIT_REEXPORT_MODULES)
|
|
||||||
)
|
)
|
||||||
for module in all_modules:
|
for module in all_modules:
|
||||||
if module.endswith(".*"):
|
if module.endswith(".*"):
|
||||||
@ -259,11 +222,6 @@ def _generate_and_validate_mypy_config(config: Config) -> str: # noqa: C901
|
|||||||
for key in STRICT_SETTINGS:
|
for key in STRICT_SETTINGS:
|
||||||
mypy_config.set(tests_section, key, "false")
|
mypy_config.set(tests_section, key, "false")
|
||||||
|
|
||||||
for ignored_module in IGNORED_MODULES:
|
|
||||||
ignored_section = f"mypy-{ignored_module}"
|
|
||||||
mypy_config.add_section(ignored_section)
|
|
||||||
mypy_config.set(ignored_section, "ignore_errors", "true")
|
|
||||||
|
|
||||||
with io.StringIO() as fp:
|
with io.StringIO() as fp:
|
||||||
mypy_config.write(fp)
|
mypy_config.write(fp)
|
||||||
fp.seek(0)
|
fp.seek(0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user