1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 12:59:34 +00:00

Enable no_implicit_reexport for core files [mypy] (#63820)

This commit is contained in:
Marc Mueller
2022-01-26 10:55:06 +01:00
committed by GitHub
parent 16e5d7abe1
commit 5e633498d2
8 changed files with 52 additions and 7 deletions

View File

@@ -81,6 +81,12 @@ IGNORED_MODULES: Final[list[str]] = [
"homeassistant.components.zwave.*",
]
# Component modules which should set no_implicit_reexport = true.
NO_IMPLICIT_REEXPORT_MODULES: set[str] = {
"homeassistant.components",
"homeassistant.components.diagnostics.*",
}
HEADER: Final = """
# Automatically generated by hassfest.
#
@@ -165,7 +171,12 @@ def generate_and_validate(config: Config) -> str:
)
# Validate that all modules exist.
all_modules = strict_modules + strict_core_modules + IGNORED_MODULES
all_modules = (
strict_modules
+ strict_core_modules
+ IGNORED_MODULES
+ list(NO_IMPLICIT_REEXPORT_MODULES)
)
for module in all_modules:
if module.endswith(".*"):
module_path = Path(module[:-2].replace(".", os.path.sep))
@@ -193,6 +204,12 @@ def generate_and_validate(config: Config) -> str:
for key in STRICT_SETTINGS:
mypy_config.set(general_section, key, "true")
# By default enable no_implicit_reexport only for homeassistant.*
# Disable it afterwards for all components
components_section = "mypy-homeassistant.*"
mypy_config.add_section(components_section)
mypy_config.set(components_section, "no_implicit_reexport", "true")
for core_module in strict_core_modules:
core_section = f"mypy-{core_module}"
mypy_config.add_section(core_section)
@@ -204,12 +221,20 @@ def generate_and_validate(config: Config) -> str:
mypy_config.add_section(components_section)
for key in STRICT_SETTINGS:
mypy_config.set(components_section, key, "false")
mypy_config.set(components_section, "no_implicit_reexport", "false")
for strict_module in strict_modules:
strict_section = f"mypy-{strict_module}"
mypy_config.add_section(strict_section)
for key in STRICT_SETTINGS:
mypy_config.set(strict_section, key, "true")
if strict_module in NO_IMPLICIT_REEXPORT_MODULES:
mypy_config.set(strict_section, "no_implicit_reexport", "true")
for reexport_module in NO_IMPLICIT_REEXPORT_MODULES.difference(strict_modules):
reexport_section = f"mypy-{reexport_module}"
mypy_config.add_section(reexport_section)
mypy_config.set(reexport_section, "no_implicit_reexport", "true")
# Disable strict checks for tests
tests_section = "mypy-tests.*"