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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 52 additions and 7 deletions

View File

@ -8,13 +8,23 @@ import voluptuous as vol
from .const import CAT_ENTITIES
from .entities import ENTITY_POLICY_SCHEMA, compile_entities
from .merge import merge_policies # noqa: F401
from .merge import merge_policies
from .models import PermissionLookup
from .types import PolicyType
from .util import test_all
POLICY_SCHEMA = vol.Schema({vol.Optional(CAT_ENTITIES): ENTITY_POLICY_SCHEMA})
__all__ = [
"POLICY_SCHEMA",
"merge_policies",
"PermissionLookup",
"PolicyType",
"AbstractPermissions",
"PolicyPermissions",
"OwnerPermissions",
]
class AbstractPermissions:
"""Default permissions class."""

View File

@ -11,7 +11,8 @@ from homeassistant.components.sensor import (
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import DATA_KILOBYTES, DATA_MEGABYTES, TIME_DAYS
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import DeviceEntryType, DeviceInfo
from homeassistant.helpers.device_registry import DeviceEntryType
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.update_coordinator import CoordinatorEntity

View File

@ -5,7 +5,7 @@ import logging
import datapoint
from homeassistant.helpers.update_coordinator import UpdateFailed
from homeassistant.util import utcnow
from homeassistant.util.dt import utcnow
from .data import MetOfficeData

View File

@ -7,7 +7,7 @@ from typing import TYPE_CHECKING
import pysma
from homeassistant.config_entries import ConfigEntry, ConfigEntryNotReady
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
CONF_HOST,
CONF_PASSWORD,
@ -17,6 +17,7 @@ from homeassistant.const import (
EVENT_HOMEASSISTANT_STOP,
)
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed

View File

@ -55,7 +55,7 @@ from homeassistant.const import (
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.temperature import convert_temperature
from homeassistant.util.temperature import convert as convert_temperature
from .const import DATA_CLIENT, DOMAIN
from .discovery import ZwaveDiscoveryInfo

View File

@ -10,7 +10,7 @@ from typing import NamedTuple
import voluptuous as vol
from homeassistant import loader
from homeassistant.config import (
from homeassistant.config import ( # type: ignore[attr-defined]
CONF_CORE,
CONF_PACKAGES,
CORE_CONFIG_SCHEMA,

View File

@ -22,6 +22,9 @@ no_implicit_optional = true
warn_return_any = true
warn_unreachable = true
[mypy-homeassistant.*]
no_implicit_reexport = true
[mypy-homeassistant.exceptions]
disallow_any_generics = true
@ -86,6 +89,7 @@ disallow_untyped_defs = false
no_implicit_optional = false
warn_return_any = false
warn_unreachable = false
no_implicit_reexport = false
[mypy-homeassistant.components]
check_untyped_defs = true
@ -97,6 +101,7 @@ disallow_untyped_defs = true
no_implicit_optional = true
warn_return_any = true
warn_unreachable = true
no_implicit_reexport = true
[mypy-homeassistant.components.abode.*]
check_untyped_defs = true
@ -2012,6 +2017,9 @@ no_implicit_optional = true
warn_return_any = true
warn_unreachable = true
[mypy-homeassistant.components.diagnostics.*]
no_implicit_reexport = true
[mypy-tests.*]
check_untyped_defs = false
disallow_incomplete_defs = false

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.*"