diff --git a/.strict-typing b/.strict-typing index 1a291f115f5a..e4e9d46847ae 100644 --- a/.strict-typing +++ b/.strict-typing @@ -2,7 +2,29 @@ # If component is fully covered with type annotations, please add it here # to enable strict mypy checks. +# Stict typing is enabled by default for core files. +# Add it here to add 'disallow_any_generics'. +# --- Only for core file! --- +homeassistant.exceptions homeassistant.core +homeassistant.loader +homeassistant.requirements +homeassistant.runner +homeassistant.setup +homeassistant.auth.auth_store +homeassistant.auth.providers.* +homeassistant.helpers.area_registry +homeassistant.helpers.condition +homeassistant.helpers.discovery +homeassistant.helpers.entity_values +homeassistant.helpers.reload +homeassistant.helpers.script_variables +homeassistant.helpers.translation +homeassistant.util.color +homeassistant.util.process +homeassistant.util.unit_system + +# --- Add components below this line --- homeassistant.components homeassistant.components.abode.* homeassistant.components.acer_projector.* diff --git a/homeassistant/auth/auth_store.py b/homeassistant/auth/auth_store.py index d1760465c321..398a4ec839ac 100644 --- a/homeassistant/auth/auth_store.py +++ b/homeassistant/auth/auth_store.py @@ -22,8 +22,6 @@ from .permissions import system_policies from .permissions.models import PermissionLookup from .permissions.types import PolicyType -# mypy: disallow-any-generics - STORAGE_VERSION = 1 STORAGE_KEY = "auth" GROUP_NAME_ADMIN = "Administrators" diff --git a/homeassistant/auth/providers/__init__.py b/homeassistant/auth/providers/__init__.py index 739681911822..b209f6b2f05a 100644 --- a/homeassistant/auth/providers/__init__.py +++ b/homeassistant/auth/providers/__init__.py @@ -22,8 +22,6 @@ from ..auth_store import AuthStore from ..const import MFA_SESSION_EXPIRATION from ..models import Credentials, RefreshToken, User, UserMeta -# mypy: disallow-any-generics - _LOGGER = logging.getLogger(__name__) DATA_REQS = "auth_prov_reqs_processed" diff --git a/homeassistant/auth/providers/command_line.py b/homeassistant/auth/providers/command_line.py index 81a6b6d78e5b..af9a01f5d9b8 100644 --- a/homeassistant/auth/providers/command_line.py +++ b/homeassistant/auth/providers/command_line.py @@ -16,8 +16,6 @@ from homeassistant.exceptions import HomeAssistantError from . import AUTH_PROVIDER_SCHEMA, AUTH_PROVIDERS, AuthProvider, LoginFlow from ..models import Credentials, UserMeta -# mypy: disallow-any-generics - CONF_ARGS = "args" CONF_META = "meta" diff --git a/homeassistant/auth/providers/homeassistant.py b/homeassistant/auth/providers/homeassistant.py index 8d682670e014..4fb12e3e7642 100644 --- a/homeassistant/auth/providers/homeassistant.py +++ b/homeassistant/auth/providers/homeassistant.py @@ -18,8 +18,6 @@ from homeassistant.exceptions import HomeAssistantError from . import AUTH_PROVIDER_SCHEMA, AUTH_PROVIDERS, AuthProvider, LoginFlow from ..models import Credentials, UserMeta -# mypy: disallow-any-generics - STORAGE_VERSION = 1 STORAGE_KEY = "auth_provider.homeassistant" diff --git a/homeassistant/auth/providers/insecure_example.py b/homeassistant/auth/providers/insecure_example.py index dc003c3e6f3c..47626686f9df 100644 --- a/homeassistant/auth/providers/insecure_example.py +++ b/homeassistant/auth/providers/insecure_example.py @@ -14,8 +14,6 @@ from homeassistant.exceptions import HomeAssistantError from . import AUTH_PROVIDER_SCHEMA, AUTH_PROVIDERS, AuthProvider, LoginFlow from ..models import Credentials, UserMeta -# mypy: disallow-any-generics - USER_SCHEMA = vol.Schema( { vol.Required("username"): str, diff --git a/homeassistant/auth/providers/legacy_api_password.py b/homeassistant/auth/providers/legacy_api_password.py index 2cb113b8b8c1..438b2148eb72 100644 --- a/homeassistant/auth/providers/legacy_api_password.py +++ b/homeassistant/auth/providers/legacy_api_password.py @@ -19,8 +19,6 @@ import homeassistant.helpers.config_validation as cv from . import AUTH_PROVIDER_SCHEMA, AUTH_PROVIDERS, AuthProvider, LoginFlow from ..models import Credentials, UserMeta -# mypy: disallow-any-generics - AUTH_PROVIDER_TYPE = "legacy_api_password" CONF_API_PASSWORD = "api_password" diff --git a/homeassistant/auth/providers/trusted_networks.py b/homeassistant/auth/providers/trusted_networks.py index d6f0c97dd0d7..cf142fa12199 100644 --- a/homeassistant/auth/providers/trusted_networks.py +++ b/homeassistant/auth/providers/trusted_networks.py @@ -27,8 +27,6 @@ from . import AUTH_PROVIDER_SCHEMA, AUTH_PROVIDERS, AuthProvider, LoginFlow from .. import InvalidAuthError from ..models import Credentials, RefreshToken, UserMeta -# mypy: disallow-any-generics - IPAddress = Union[IPv4Address, IPv6Address] IPNetwork = Union[IPv4Network, IPv6Network] diff --git a/homeassistant/exceptions.py b/homeassistant/exceptions.py index 2a82c2652edb..ff8fb295cd5b 100644 --- a/homeassistant/exceptions.py +++ b/homeassistant/exceptions.py @@ -9,8 +9,6 @@ import attr if TYPE_CHECKING: from .core import Context -# mypy: disallow-any-generics - class HomeAssistantError(Exception): """General Home Assistant exception occurred.""" diff --git a/homeassistant/helpers/area_registry.py b/homeassistant/helpers/area_registry.py index 8c4179dd9405..3f3e526b0c2b 100644 --- a/homeassistant/helpers/area_registry.py +++ b/homeassistant/helpers/area_registry.py @@ -14,8 +14,6 @@ from homeassistant.util import slugify from . import device_registry as dr, entity_registry as er from .typing import UNDEFINED, UndefinedType -# mypy: disallow-any-generics - DATA_REGISTRY = "area_registry" EVENT_AREA_REGISTRY_UPDATED = "area_registry_updated" STORAGE_KEY = "core.area_registry" diff --git a/homeassistant/helpers/condition.py b/homeassistant/helpers/condition.py index 0fc2ade17469..d1ece8a85df9 100644 --- a/homeassistant/helpers/condition.py +++ b/homeassistant/helpers/condition.py @@ -70,8 +70,6 @@ from .trace import ( ) from .typing import ConfigType, TemplateVarsType -# mypy: disallow-any-generics - ASYNC_FROM_CONFIG_FORMAT = "async_{}_from_config" FROM_CONFIG_FORMAT = "{}_from_config" VALIDATE_CONFIG_FORMAT = "{}_validate_config" diff --git a/homeassistant/helpers/discovery.py b/homeassistant/helpers/discovery.py index 73d2aec46056..63f6c3395e95 100644 --- a/homeassistant/helpers/discovery.py +++ b/homeassistant/helpers/discovery.py @@ -23,8 +23,6 @@ EVENT_LOAD_PLATFORM = "load_platform.{}" ATTR_PLATFORM = "platform" ATTR_DISCOVERED = "discovered" -# mypy: disallow-any-generics - class DiscoveryDict(TypedDict): """Discovery data.""" diff --git a/homeassistant/helpers/entity_values.py b/homeassistant/helpers/entity_values.py index 8f11fbf31161..d489a4b1d379 100644 --- a/homeassistant/helpers/entity_values.py +++ b/homeassistant/helpers/entity_values.py @@ -8,8 +8,6 @@ from typing import Any from homeassistant.core import split_entity_id -# mypy: disallow-any-generics - class EntityValues: """Class to store entity id based values.""" diff --git a/homeassistant/helpers/reload.py b/homeassistant/helpers/reload.py index a0388f53a936..5a826d4129e1 100644 --- a/homeassistant/helpers/reload.py +++ b/homeassistant/helpers/reload.py @@ -17,8 +17,6 @@ from . import config_per_platform from .entity_platform import EntityPlatform, async_get_platforms from .typing import ConfigType -# mypy: disallow-any-generics - _LOGGER = logging.getLogger(__name__) diff --git a/homeassistant/helpers/script_variables.py b/homeassistant/helpers/script_variables.py index 3dae84166f6b..6c5edfd0ac36 100644 --- a/homeassistant/helpers/script_variables.py +++ b/homeassistant/helpers/script_variables.py @@ -8,8 +8,6 @@ from homeassistant.core import HomeAssistant, callback from . import template -# mypy: disallow-any-generics - class ScriptVariables: """Class to hold and render script variables.""" diff --git a/homeassistant/helpers/translation.py b/homeassistant/helpers/translation.py index e10c814389be..2f20e1404d81 100644 --- a/homeassistant/helpers/translation.py +++ b/homeassistant/helpers/translation.py @@ -17,8 +17,6 @@ from homeassistant.loader import ( from homeassistant.util.async_ import gather_with_concurrency from homeassistant.util.json import load_json -# mypy: disallow-any-generics - _LOGGER = logging.getLogger(__name__) TRANSLATION_LOAD_LOCK = "translation_load_lock" diff --git a/homeassistant/loader.py b/homeassistant/loader.py index 5a2248dab43c..050000327963 100644 --- a/homeassistant/loader.py +++ b/homeassistant/loader.py @@ -34,8 +34,6 @@ from .util.async_ import gather_with_concurrency if TYPE_CHECKING: from .core import HomeAssistant -# mypy: disallow-any-generics - CALLABLE_T = TypeVar( # pylint: disable=invalid-name "CALLABLE_T", bound=Callable[..., Any] ) diff --git a/homeassistant/requirements.py b/homeassistant/requirements.py index 6b9c0bd06614..7631586d6260 100644 --- a/homeassistant/requirements.py +++ b/homeassistant/requirements.py @@ -13,8 +13,6 @@ from .helpers.typing import UNDEFINED, UndefinedType from .loader import Integration, IntegrationNotFound, async_get_integration from .util import package as pkg_util -# mypy: disallow-any-generics - PIP_TIMEOUT = 60 # The default is too low when the internet connection is satellite or high latency MAX_INSTALL_FAILURES = 3 DATA_PIP_LOCK = "pip_lock" diff --git a/homeassistant/runner.py b/homeassistant/runner.py index 7caf6be2c8f9..571111d10772 100644 --- a/homeassistant/runner.py +++ b/homeassistant/runner.py @@ -14,8 +14,6 @@ from .helpers.frame import warn_use from .util.executor import InterruptibleThreadPoolExecutor from .util.thread import deadlock_safe_shutdown -# mypy: disallow-any-generics - # # Python 3.8 has significantly less workers by default # than Python 3.7. In order to be consistent between diff --git a/homeassistant/setup.py b/homeassistant/setup.py index f694e7a79c6b..1c3702a4725d 100644 --- a/homeassistant/setup.py +++ b/homeassistant/setup.py @@ -22,8 +22,6 @@ from .exceptions import HomeAssistantError from .helpers.typing import ConfigType from .util import dt as dt_util, ensure_unique_string -# mypy: disallow-any-generics - _LOGGER = logging.getLogger(__name__) ATTR_COMPONENT = "component" diff --git a/homeassistant/util/color.py b/homeassistant/util/color.py index 9c01c3040c23..f308595adbdc 100644 --- a/homeassistant/util/color.py +++ b/homeassistant/util/color.py @@ -7,8 +7,6 @@ from typing import NamedTuple, cast import attr -# mypy: disallow-any-generics - class RGBColor(NamedTuple): """RGB hex values.""" diff --git a/homeassistant/util/process.py b/homeassistant/util/process.py index 832ef450dca9..3affa28e9096 100644 --- a/homeassistant/util/process.py +++ b/homeassistant/util/process.py @@ -5,8 +5,6 @@ from __future__ import annotations import subprocess from typing import Any -# mypy: disallow-any-generics - def kill_subprocess(process: subprocess.Popen[Any]) -> None: """Force kill a subprocess and wait for it to exit.""" diff --git a/homeassistant/util/unit_system.py b/homeassistant/util/unit_system.py index 824e324095db..dfe73b0e937a 100644 --- a/homeassistant/util/unit_system.py +++ b/homeassistant/util/unit_system.py @@ -40,8 +40,6 @@ from . import ( volume as volume_util, ) -# mypy: disallow-any-generics - LENGTH_UNITS = distance_util.VALID_UNITS MASS_UNITS: tuple[str, ...] = (MASS_POUNDS, MASS_OUNCES, MASS_KILOGRAMS, MASS_GRAMS) diff --git a/mypy.ini b/mypy.ini index 6d13e0a1c213..31d929d39d84 100644 --- a/mypy.ini +++ b/mypy.ini @@ -22,9 +22,60 @@ no_implicit_optional = true warn_return_any = true warn_unreachable = true +[mypy-homeassistant.exceptions] +disallow_any_generics = true + [mypy-homeassistant.core] disallow_any_generics = true +[mypy-homeassistant.loader] +disallow_any_generics = true + +[mypy-homeassistant.requirements] +disallow_any_generics = true + +[mypy-homeassistant.runner] +disallow_any_generics = true + +[mypy-homeassistant.setup] +disallow_any_generics = true + +[mypy-homeassistant.auth.auth_store] +disallow_any_generics = true + +[mypy-homeassistant.auth.providers.*] +disallow_any_generics = true + +[mypy-homeassistant.helpers.area_registry] +disallow_any_generics = true + +[mypy-homeassistant.helpers.condition] +disallow_any_generics = true + +[mypy-homeassistant.helpers.discovery] +disallow_any_generics = true + +[mypy-homeassistant.helpers.entity_values] +disallow_any_generics = true + +[mypy-homeassistant.helpers.reload] +disallow_any_generics = true + +[mypy-homeassistant.helpers.script_variables] +disallow_any_generics = true + +[mypy-homeassistant.helpers.translation] +disallow_any_generics = true + +[mypy-homeassistant.util.color] +disallow_any_generics = true + +[mypy-homeassistant.util.process] +disallow_any_generics = true + +[mypy-homeassistant.util.unit_system] +disallow_any_generics = true + [mypy-homeassistant.components.*] check_untyped_defs = false disallow_incomplete_defs = false