diff --git a/homeassistant/helpers/config_entry_oauth2_flow.py b/homeassistant/helpers/config_entry_oauth2_flow.py index 9baed41dd20c4ddea6b129ac88e0d626bf87d4f2..5214c8cbc3c25861df97e0c9ec49ca683e53c545 100644 --- a/homeassistant/helpers/config_entry_oauth2_flow.py +++ b/homeassistant/helpers/config_entry_oauth2_flow.py @@ -196,7 +196,9 @@ class AbstractOAuth2FlowHandler(config_entries.ConfigFlow, metaclass=ABCMeta): """Extra data that needs to be appended to the authorize url.""" return {} - async def async_step_pick_implementation(self, user_input: dict = None) -> dict: + async def async_step_pick_implementation( + self, user_input: Optional[dict] = None + ) -> dict: """Handle a flow start.""" assert self.hass implementations = await async_get_implementations(self.hass, self.DOMAIN) @@ -224,7 +226,7 @@ class AbstractOAuth2FlowHandler(config_entries.ConfigFlow, metaclass=ABCMeta): ), ) - async def async_step_auth(self, user_input: dict = None) -> dict: + async def async_step_auth(self, user_input: Optional[dict] = None) -> dict: """Create an entry for auth.""" # Flow has been triggered by external data if user_input: @@ -241,7 +243,7 @@ class AbstractOAuth2FlowHandler(config_entries.ConfigFlow, metaclass=ABCMeta): return self.async_external_step(step_id="auth", url=url) - async def async_step_creation(self, user_input: dict = None) -> dict: + async def async_step_creation(self, user_input: Optional[dict] = None) -> dict: """Create config entry from external data.""" token = await self.flow_impl.async_resolve_external_data(self.external_data) token["expires_at"] = time.time() + token["expires_in"] @@ -259,7 +261,7 @@ class AbstractOAuth2FlowHandler(config_entries.ConfigFlow, metaclass=ABCMeta): """ return self.async_create_entry(title=self.flow_impl.name, data=data) - async def async_step_discovery(self, user_input: dict = None) -> dict: + async def async_step_discovery(self, user_input: Optional[dict] = None) -> dict: """Handle a flow initialized by discovery.""" await self.async_set_unique_id(self.DOMAIN) diff --git a/homeassistant/helpers/config_validation.py b/homeassistant/helpers/config_validation.py index db966d934123c04964b685bc6002dc33a1543b5d..7bb3223f3d73f9110b07c6129dadd3e9bdc96ef6 100644 --- a/homeassistant/helpers/config_validation.py +++ b/homeassistant/helpers/config_validation.py @@ -338,7 +338,7 @@ def date(value: Any) -> date_sys: def time_period_str(value: str) -> timedelta: """Validate and transform time offset.""" - if isinstance(value, int): + if isinstance(value, int): # type: ignore raise vol.Invalid("Make sure you wrap time values in quotes") if not isinstance(value, str): raise vol.Invalid(TIME_PERIOD_ERROR.format(value)) diff --git a/homeassistant/helpers/logging.py b/homeassistant/helpers/logging.py index 2e3270879f084e90564e99c1e7085ae3e3fbaa3c..49b9bfcffec6f683f6ce9bd372e1b74d53620b91 100644 --- a/homeassistant/helpers/logging.py +++ b/homeassistant/helpers/logging.py @@ -35,7 +35,7 @@ class KeywordStyleAdapter(logging.LoggerAdapter): """Log the message provided at the appropriate level.""" if self.isEnabledFor(level): msg, log_kwargs = self.process(msg, kwargs) - self.logger._log( # type: ignore # pylint: disable=protected-access + self.logger._log( # pylint: disable=protected-access level, KeywordMessage(msg, args, kwargs), (), **log_kwargs ) @@ -48,7 +48,7 @@ class KeywordStyleAdapter(logging.LoggerAdapter): { k: kwargs[k] for k in inspect.getfullargspec( - self.logger._log # type: ignore # pylint: disable=protected-access + self.logger._log # pylint: disable=protected-access ).args[1:] if k in kwargs }, diff --git a/homeassistant/helpers/temperature.py b/homeassistant/helpers/temperature.py index e0846d6f893cac38b723d190257752132c062daa..18ca8355159199c0759b75204c148518dcac880a 100644 --- a/homeassistant/helpers/temperature.py +++ b/homeassistant/helpers/temperature.py @@ -22,8 +22,7 @@ def display_temp( if not isinstance(temperature, Number): raise TypeError(f"Temperature is not a number: {temperature}") - # type ignore: https://github.com/python/mypy/issues/7207 - if temperature_unit != ha_unit: # type: ignore + if temperature_unit != ha_unit: temperature = convert_temperature(temperature, temperature_unit, ha_unit) # Round in the units appropriate diff --git a/homeassistant/helpers/template.py b/homeassistant/helpers/template.py index e7f89b482e2f4fc7d28cc49049a26469764ca8f8..5cd15fefd99a6bc81c3902e94b6bffb773db68df 100644 --- a/homeassistant/helpers/template.py +++ b/homeassistant/helpers/template.py @@ -192,7 +192,7 @@ class Template: raise TemplateError(err) def extract_entities( - self, variables: Dict[str, Any] = None + self, variables: Optional[Dict[str, Any]] = None ) -> Union[str, List[str]]: """Extract all entities for state_changed listener.""" return extract_entities(self.template, variables) diff --git a/homeassistant/requirements.py b/homeassistant/requirements.py index 7b2d3fe9bc316682e784a98013458b2bcf1aea02..317fffe84bf8635ca67ccd8732d8158c1b2db40a 100644 --- a/homeassistant/requirements.py +++ b/homeassistant/requirements.py @@ -32,7 +32,7 @@ class RequirementsNotFound(HomeAssistantError): async def async_get_integration_with_requirements( - hass: HomeAssistant, domain: str, done: Set[str] = None + hass: HomeAssistant, domain: str, done: Optional[Set[str]] = None ) -> Integration: """Get an integration with all requirements installed, including the dependencies. diff --git a/homeassistant/scripts/benchmark/__init__.py b/homeassistant/scripts/benchmark/__init__.py index 2c885dd171303eca917ad6f6b2ec51d5e4af1a14..2bc821c84955cd1e8ec5f205fdce2e13b1e7a1c8 100644 --- a/homeassistant/scripts/benchmark/__init__.py +++ b/homeassistant/scripts/benchmark/__init__.py @@ -5,7 +5,7 @@ from contextlib import suppress from datetime import datetime import logging from timeit import default_timer as timer -from typing import Callable, Dict +from typing import Callable, Dict, TypeVar from homeassistant import core from homeassistant.components.websocket_api.const import JSON_DUMP @@ -15,6 +15,8 @@ from homeassistant.util import dt as dt_util # mypy: allow-untyped-calls, allow-untyped-defs, no-check-untyped-defs # mypy: no-warn-return-any +CALLABLE_T = TypeVar("CALLABLE_T", bound=Callable) # pylint: disable=invalid-name + BENCHMARKS: Dict[str, Callable] = {} @@ -44,7 +46,7 @@ def run(args): loop.close() -def benchmark(func): +def benchmark(func: CALLABLE_T) -> CALLABLE_T: """Decorate to mark a benchmark.""" BENCHMARKS[func.__name__] = func return func diff --git a/homeassistant/util/distance.py b/homeassistant/util/distance.py index 4fdc40bde2ffd33492fccd2f204979d896708749..70fc9ad4eaa1e5ac6fe2391cb798924c5a2636c4 100644 --- a/homeassistant/util/distance.py +++ b/homeassistant/util/distance.py @@ -27,11 +27,10 @@ def convert(value: float, unit_1: str, unit_2: str) -> float: if not isinstance(value, Number): raise TypeError(f"{value} is not of numeric type") - # type ignore: https://github.com/python/mypy/issues/7207 - if unit_1 == unit_2 or unit_1 not in VALID_UNITS: # type: ignore + if unit_1 == unit_2 or unit_1 not in VALID_UNITS: return value - meters = value + meters: float = value if unit_1 == LENGTH_MILES: meters = __miles_to_meters(value) diff --git a/homeassistant/util/pressure.py b/homeassistant/util/pressure.py index df791fd02353bc56a7ebce0067098849ec7287ba..046b65122a97298a42e9f8be3fb5c98f7d570219 100644 --- a/homeassistant/util/pressure.py +++ b/homeassistant/util/pressure.py @@ -36,8 +36,7 @@ def convert(value: float, unit_1: str, unit_2: str) -> float: if not isinstance(value, Number): raise TypeError(f"{value} is not of numeric type") - # type ignore: https://github.com/python/mypy/issues/7207 - if unit_1 == unit_2 or unit_1 not in VALID_UNITS: # type: ignore + if unit_1 == unit_2 or unit_1 not in VALID_UNITS: return value pascals = value / UNIT_CONVERSION[unit_1] diff --git a/homeassistant/util/ruamel_yaml.py b/homeassistant/util/ruamel_yaml.py index 68a357d91f6ebc22ccb2023836dd514e54ed09e1..71d3ab2cc4334870bd9f12bbd5ddb0b0a096e3e8 100644 --- a/homeassistant/util/ruamel_yaml.py +++ b/homeassistant/util/ruamel_yaml.py @@ -6,7 +6,7 @@ from os import O_CREAT, O_TRUNC, O_WRONLY, stat_result from typing import Dict, List, Optional, Union import ruamel.yaml -from ruamel.yaml import YAML +from ruamel.yaml import YAML # type: ignore from ruamel.yaml.compat import StringIO from ruamel.yaml.constructor import SafeConstructor from ruamel.yaml.error import YAMLError @@ -89,8 +89,7 @@ def load_yaml(fname: str, round_trip: bool = False) -> JSON_TYPE: """Load a YAML file.""" if round_trip: yaml = YAML(typ="rt") - # type ignore: https://bitbucket.org/ruamel/yaml/pull-requests/42 - yaml.preserve_quotes = True # type: ignore + yaml.preserve_quotes = True else: if ExtSafeConstructor.name is None: ExtSafeConstructor.name = fname diff --git a/homeassistant/util/unit_system.py b/homeassistant/util/unit_system.py index 5540936c8b4b4f47aec963e2955988b050251f2f..8b276da432d2632977d2e3efd0fe43bf2848ad61 100644 --- a/homeassistant/util/unit_system.py +++ b/homeassistant/util/unit_system.py @@ -109,10 +109,7 @@ class UnitSystem: if not isinstance(temperature, Number): raise TypeError(f"{temperature!s} is not a numeric value.") - # type ignore: https://github.com/python/mypy/issues/7207 - return temperature_util.convert( # type: ignore - temperature, from_unit, self.temperature_unit - ) + return temperature_util.convert(temperature, from_unit, self.temperature_unit) def length(self, length: Optional[float], from_unit: str) -> float: """Convert the given length to this unit system.""" diff --git a/homeassistant/util/volume.py b/homeassistant/util/volume.py index 2e033beb35cb5bb16d3722d93ab18e9e0594111c..30185e4346cbbc3515aa026380f2f9a2649f6f4f 100644 --- a/homeassistant/util/volume.py +++ b/homeassistant/util/volume.py @@ -37,11 +37,10 @@ def convert(volume: float, from_unit: str, to_unit: str) -> float: if not isinstance(volume, Number): raise TypeError(f"{volume} is not of numeric type") - # type ignore: https://github.com/python/mypy/issues/7207 - if from_unit == to_unit: # type: ignore + if from_unit == to_unit: return volume - result = volume + result: float = volume if from_unit == VOLUME_LITERS and to_unit == VOLUME_GALLONS: result = __liter_to_gallon(volume) elif from_unit == VOLUME_GALLONS and to_unit == VOLUME_LITERS: diff --git a/requirements_test.txt b/requirements_test.txt index 6fc7e10a78dba3d339811c02669b35f6447c8803..dbc756ff7c806fc7a098cb303a24cfd7950ebec0 100644 --- a/requirements_test.txt +++ b/requirements_test.txt @@ -6,7 +6,7 @@ asynctest==0.13.0 codecov==2.0.15 mock-open==1.3.1 -mypy==0.761 +mypy==0.770 pre-commit==2.1.1 pylint==2.4.4 astroid==2.3.3 diff --git a/setup.cfg b/setup.cfg index f9e9852812c8abc798e5eda01b32f955db798123..7df396df528e66627ca3610643870c13b1a38ca9 100644 --- a/setup.cfg +++ b/setup.cfg @@ -65,13 +65,9 @@ warn_redundant_casts = true warn_unused_configs = true [mypy-homeassistant.bootstrap,homeassistant.components,homeassistant.config_entries,homeassistant.config,homeassistant.const,homeassistant.core,homeassistant.data_entry_flow,homeassistant.exceptions,homeassistant.loader,homeassistant.__main__,homeassistant.requirements,homeassistant.setup,homeassistant.util,homeassistant.auth.*,homeassistant.components.automation.*,homeassistant.components.binary_sensor.*,homeassistant.components.calendar.*,homeassistant.components.cover.*,homeassistant.components.device_automation.*,homeassistant.components.frontend.*,homeassistant.components.geo_location.*,homeassistant.components.group.*,homeassistant.components.history.*,homeassistant.components.http.*,homeassistant.components.image_processing.*,homeassistant.components.integration.*,homeassistant.components.light.*,homeassistant.components.lock.*,homeassistant.components.mailbox.*,homeassistant.components.media_player.*,homeassistant.components.notify.*,homeassistant.components.persistent_notification.*,homeassistant.components.proximity.*,homeassistant.components.remote.*,homeassistant.components.scene.*,homeassistant.components.sensor.*,homeassistant.components.sun.*,homeassistant.components.switch.*,homeassistant.components.systemmonitor.*,homeassistant.components.tts.*,homeassistant.components.vacuum.*,homeassistant.components.water_heater.*,homeassistant.components.weather.*,homeassistant.components.websocket_api.*,homeassistant.components.zone.*,homeassistant.helpers.*,homeassistant.scripts.*,homeassistant.util.*] +strict = true ignore_errors = false -check_untyped_defs = true -disallow_incomplete_defs = true -disallow_untyped_calls = true -disallow_untyped_defs = true -no_implicit_optional = true -strict_equality = true -warn_return_any = true warn_unreachable = true -warn_unused_ignores = true +# TODO: turn these off, address issues +allow_any_generics = true +implicit_reexport = true