mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
Enable no_implicit_reexport
for core files [mypy] (#63820)
This commit is contained in:
parent
16e5d7abe1
commit
5e633498d2
@ -8,13 +8,23 @@ import voluptuous as vol
|
|||||||
|
|
||||||
from .const import CAT_ENTITIES
|
from .const import CAT_ENTITIES
|
||||||
from .entities import ENTITY_POLICY_SCHEMA, compile_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 .models import PermissionLookup
|
||||||
from .types import PolicyType
|
from .types import PolicyType
|
||||||
from .util import test_all
|
from .util import test_all
|
||||||
|
|
||||||
POLICY_SCHEMA = vol.Schema({vol.Optional(CAT_ENTITIES): ENTITY_POLICY_SCHEMA})
|
POLICY_SCHEMA = vol.Schema({vol.Optional(CAT_ENTITIES): ENTITY_POLICY_SCHEMA})
|
||||||
|
|
||||||
|
__all__ = [
|
||||||
|
"POLICY_SCHEMA",
|
||||||
|
"merge_policies",
|
||||||
|
"PermissionLookup",
|
||||||
|
"PolicyType",
|
||||||
|
"AbstractPermissions",
|
||||||
|
"PolicyPermissions",
|
||||||
|
"OwnerPermissions",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
class AbstractPermissions:
|
class AbstractPermissions:
|
||||||
"""Default permissions class."""
|
"""Default permissions class."""
|
||||||
|
@ -11,7 +11,8 @@ from homeassistant.components.sensor import (
|
|||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import DATA_KILOBYTES, DATA_MEGABYTES, TIME_DAYS
|
from homeassistant.const import DATA_KILOBYTES, DATA_MEGABYTES, TIME_DAYS
|
||||||
from homeassistant.core import HomeAssistant
|
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.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ import logging
|
|||||||
import datapoint
|
import datapoint
|
||||||
|
|
||||||
from homeassistant.helpers.update_coordinator import UpdateFailed
|
from homeassistant.helpers.update_coordinator import UpdateFailed
|
||||||
from homeassistant.util import utcnow
|
from homeassistant.util.dt import utcnow
|
||||||
|
|
||||||
from .data import MetOfficeData
|
from .data import MetOfficeData
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ from typing import TYPE_CHECKING
|
|||||||
|
|
||||||
import pysma
|
import pysma
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry, ConfigEntryNotReady
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONF_HOST,
|
CONF_HOST,
|
||||||
CONF_PASSWORD,
|
CONF_PASSWORD,
|
||||||
@ -17,6 +17,7 @@ from homeassistant.const import (
|
|||||||
EVENT_HOMEASSISTANT_STOP,
|
EVENT_HOMEASSISTANT_STOP,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.exceptions import ConfigEntryNotReady
|
||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
from homeassistant.helpers.entity import DeviceInfo
|
from homeassistant.helpers.entity import DeviceInfo
|
||||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||||
|
@ -55,7 +55,7 @@ from homeassistant.const import (
|
|||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
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 .const import DATA_CLIENT, DOMAIN
|
||||||
from .discovery import ZwaveDiscoveryInfo
|
from .discovery import ZwaveDiscoveryInfo
|
||||||
|
@ -10,7 +10,7 @@ from typing import NamedTuple
|
|||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant import loader
|
from homeassistant import loader
|
||||||
from homeassistant.config import (
|
from homeassistant.config import ( # type: ignore[attr-defined]
|
||||||
CONF_CORE,
|
CONF_CORE,
|
||||||
CONF_PACKAGES,
|
CONF_PACKAGES,
|
||||||
CORE_CONFIG_SCHEMA,
|
CORE_CONFIG_SCHEMA,
|
||||||
|
8
mypy.ini
8
mypy.ini
@ -22,6 +22,9 @@ no_implicit_optional = true
|
|||||||
warn_return_any = true
|
warn_return_any = true
|
||||||
warn_unreachable = true
|
warn_unreachable = true
|
||||||
|
|
||||||
|
[mypy-homeassistant.*]
|
||||||
|
no_implicit_reexport = true
|
||||||
|
|
||||||
[mypy-homeassistant.exceptions]
|
[mypy-homeassistant.exceptions]
|
||||||
disallow_any_generics = true
|
disallow_any_generics = true
|
||||||
|
|
||||||
@ -86,6 +89,7 @@ disallow_untyped_defs = false
|
|||||||
no_implicit_optional = false
|
no_implicit_optional = false
|
||||||
warn_return_any = false
|
warn_return_any = false
|
||||||
warn_unreachable = false
|
warn_unreachable = false
|
||||||
|
no_implicit_reexport = false
|
||||||
|
|
||||||
[mypy-homeassistant.components]
|
[mypy-homeassistant.components]
|
||||||
check_untyped_defs = true
|
check_untyped_defs = true
|
||||||
@ -97,6 +101,7 @@ disallow_untyped_defs = true
|
|||||||
no_implicit_optional = true
|
no_implicit_optional = true
|
||||||
warn_return_any = true
|
warn_return_any = true
|
||||||
warn_unreachable = true
|
warn_unreachable = true
|
||||||
|
no_implicit_reexport = true
|
||||||
|
|
||||||
[mypy-homeassistant.components.abode.*]
|
[mypy-homeassistant.components.abode.*]
|
||||||
check_untyped_defs = true
|
check_untyped_defs = true
|
||||||
@ -2012,6 +2017,9 @@ no_implicit_optional = true
|
|||||||
warn_return_any = true
|
warn_return_any = true
|
||||||
warn_unreachable = true
|
warn_unreachable = true
|
||||||
|
|
||||||
|
[mypy-homeassistant.components.diagnostics.*]
|
||||||
|
no_implicit_reexport = true
|
||||||
|
|
||||||
[mypy-tests.*]
|
[mypy-tests.*]
|
||||||
check_untyped_defs = false
|
check_untyped_defs = false
|
||||||
disallow_incomplete_defs = false
|
disallow_incomplete_defs = false
|
||||||
|
@ -81,6 +81,12 @@ IGNORED_MODULES: Final[list[str]] = [
|
|||||||
"homeassistant.components.zwave.*",
|
"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 = """
|
HEADER: Final = """
|
||||||
# Automatically generated by hassfest.
|
# Automatically generated by hassfest.
|
||||||
#
|
#
|
||||||
@ -165,7 +171,12 @@ def generate_and_validate(config: Config) -> str:
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Validate that all modules exist.
|
# 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:
|
for module in all_modules:
|
||||||
if module.endswith(".*"):
|
if module.endswith(".*"):
|
||||||
module_path = Path(module[:-2].replace(".", os.path.sep))
|
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:
|
for key in STRICT_SETTINGS:
|
||||||
mypy_config.set(general_section, key, "true")
|
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:
|
for core_module in strict_core_modules:
|
||||||
core_section = f"mypy-{core_module}"
|
core_section = f"mypy-{core_module}"
|
||||||
mypy_config.add_section(core_section)
|
mypy_config.add_section(core_section)
|
||||||
@ -204,12 +221,20 @@ def generate_and_validate(config: Config) -> str:
|
|||||||
mypy_config.add_section(components_section)
|
mypy_config.add_section(components_section)
|
||||||
for key in STRICT_SETTINGS:
|
for key in STRICT_SETTINGS:
|
||||||
mypy_config.set(components_section, key, "false")
|
mypy_config.set(components_section, key, "false")
|
||||||
|
mypy_config.set(components_section, "no_implicit_reexport", "false")
|
||||||
|
|
||||||
for strict_module in strict_modules:
|
for strict_module in strict_modules:
|
||||||
strict_section = f"mypy-{strict_module}"
|
strict_section = f"mypy-{strict_module}"
|
||||||
mypy_config.add_section(strict_section)
|
mypy_config.add_section(strict_section)
|
||||||
for key in STRICT_SETTINGS:
|
for key in STRICT_SETTINGS:
|
||||||
mypy_config.set(strict_section, key, "true")
|
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
|
# Disable strict checks for tests
|
||||||
tests_section = "mypy-tests.*"
|
tests_section = "mypy-tests.*"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user