Upgrade mypy to 0.770, tighten config a bit (#32715)
* Upgrade mypy to 0.770, related cleanups https://mypy-lang.blogspot.com/2020/03/mypy-0770-released.html * Clean up config and make it a notch stricter, address findings
This commit is contained in:
parent
77ebda0c20
commit
221d5205e4
14 changed files with 29 additions and 37 deletions
|
@ -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)
|
||||
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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
|
||||
},
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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.
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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."""
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
|
12
setup.cfg
12
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
|
||||
|
|
Loading…
Add table
Reference in a new issue