Update Mypy to 0.950 (#70948)

Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
Marc Mueller 2022-04-28 03:49:54 +02:00 committed by GitHub
parent 27a5851ee2
commit 93cbb331e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 45 additions and 39 deletions

View File

@ -67,8 +67,8 @@ _P = ParamSpec("_P")
def catch_request_errors( def catch_request_errors(
func: Callable[Concatenate[_T, _P], Awaitable[_R]] # type: ignore[misc] func: Callable[Concatenate[_T, _P], Awaitable[_R]]
) -> Callable[Concatenate[_T, _P], Coroutine[Any, Any, _R | None]]: # type: ignore[misc] ) -> Callable[Concatenate[_T, _P], Coroutine[Any, Any, _R | None]]:
"""Catch UpnpError errors.""" """Catch UpnpError errors."""
@functools.wraps(func) @functools.wraps(func)
@ -80,7 +80,7 @@ def catch_request_errors(
) )
return None return None
try: try:
return await func(self, *args, **kwargs) # type: ignore[no-any-return] # mypy can't yet infer 'func' return await func(self, *args, **kwargs)
except UpnpError as err: except UpnpError as err:
self.check_available = True self.check_available = True
_LOGGER.error("Error during call %s: %r", func.__name__, err) _LOGGER.error("Error during call %s: %r", func.__name__, err)

View File

@ -15,8 +15,8 @@ _P = ParamSpec("_P")
def update_when_done( def update_when_done(
func: Callable[Concatenate[_T, _P], Awaitable[_R]] # type: ignore[misc] func: Callable[Concatenate[_T, _P], Awaitable[_R]]
) -> Callable[Concatenate[_T, _P], Coroutine[Any, Any, _R]]: # type: ignore[misc] ) -> Callable[Concatenate[_T, _P], Coroutine[Any, Any, _R]]:
"""Decorate function to trigger update when function is done.""" """Decorate function to trigger update when function is done."""
@wraps(func) @wraps(func)
@ -24,6 +24,6 @@ def update_when_done(
"""Wrap function.""" """Wrap function."""
result = await func(self, *args, **kwargs) result = await func(self, *args, **kwargs)
await self.coordinator.async_request_refresh() await self.coordinator.async_request_refresh()
return result # type: ignore[no-any-return] # mypy can't yet infer 'func' return result
return wrapper return wrapper

View File

@ -96,7 +96,7 @@ def async_user_not_allowed_do_auth(
return "User is local only" return "User is local only"
try: try:
remote = ip_address(request.remote) remote = ip_address(request.remote) # type: ignore[arg-type]
except ValueError: except ValueError:
return "Invalid remote IP" return "Invalid remote IP"

View File

@ -67,7 +67,7 @@ async def ban_middleware(
return await handler(request) return await handler(request)
# Verify if IP is not banned # Verify if IP is not banned
ip_address_ = ip_address(request.remote) ip_address_ = ip_address(request.remote) # type: ignore[arg-type]
is_banned = any( is_banned = any(
ip_ban.ip_address == ip_address_ for ip_ban in request.app[KEY_BANNED_IPS] ip_ban.ip_address == ip_address_ for ip_ban in request.app[KEY_BANNED_IPS]
) )
@ -107,7 +107,7 @@ async def process_wrong_login(request: Request) -> None:
""" """
hass = request.app["hass"] hass = request.app["hass"]
remote_addr = ip_address(request.remote) remote_addr = ip_address(request.remote) # type: ignore[arg-type]
remote_host = request.remote remote_host = request.remote
with suppress(herror): with suppress(herror):
remote_host, _, _ = await hass.async_add_executor_job( remote_host, _, _ = await hass.async_add_executor_job(
@ -170,7 +170,7 @@ async def process_success_login(request: Request) -> None:
No release IP address from banned list function, it can only be done by No release IP address from banned list function, it can only be done by
manual modify ip bans config file. manual modify ip bans config file.
""" """
remote_addr = ip_address(request.remote) remote_addr = ip_address(request.remote) # type: ignore[arg-type]
# Check if ban middleware is loaded # Check if ban middleware is loaded
if KEY_BANNED_IPS not in request.app or request.app[KEY_LOGIN_THRESHOLD] < 1: if KEY_BANNED_IPS not in request.app or request.app[KEY_LOGIN_THRESHOLD] < 1:

View File

@ -15,8 +15,8 @@ _T = TypeVar("_T", bound=PlugwiseEntity)
def plugwise_command( def plugwise_command(
func: Callable[Concatenate[_T, _P], Awaitable[_R]] # type: ignore[misc] func: Callable[Concatenate[_T, _P], Awaitable[_R]]
) -> Callable[Concatenate[_T, _P], Coroutine[Any, Any, _R]]: # type: ignore[misc] ) -> Callable[Concatenate[_T, _P], Coroutine[Any, Any, _R]]:
"""Decorate Plugwise calls that send commands/make changes to the device. """Decorate Plugwise calls that send commands/make changes to the device.
A decorator that wraps the passed in function, catches Plugwise errors, A decorator that wraps the passed in function, catches Plugwise errors,

View File

@ -29,8 +29,8 @@ def roku_exception_handler(ignore_timeout: bool = False) -> Callable[..., Callab
"""Decorate Roku calls to handle Roku exceptions.""" """Decorate Roku calls to handle Roku exceptions."""
def decorator( def decorator(
func: Callable[Concatenate[_T, _P], Awaitable[None]], # type: ignore[misc] func: Callable[Concatenate[_T, _P], Awaitable[None]],
) -> Callable[Concatenate[_T, _P], Coroutine[Any, Any, None]]: # type: ignore[misc] ) -> Callable[Concatenate[_T, _P], Coroutine[Any, Any, None]]:
@wraps(func) @wraps(func)
async def wrapper(self: _T, *args: _P.args, **kwargs: _P.kwargs) -> None: async def wrapper(self: _T, *args: _P.args, **kwargs: _P.kwargs) -> None:
try: try:

View File

@ -79,7 +79,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
), ),
} }
sentry_sdk.init( # pylint: disable=abstract-class-instantiated # pylint: disable-next=abstract-class-instantiated
sentry_sdk.init( # type: ignore[abstract]
dsn=entry.data[CONF_DSN], dsn=entry.data[CONF_DSN],
environment=entry.options.get(CONF_ENVIRONMENT), environment=entry.options.get(CONF_ENVIRONMENT),
integrations=[sentry_logging, AioHttpIntegration(), SqlalchemyIntegration()], integrations=[sentry_logging, AioHttpIntegration(), SqlalchemyIntegration()],

View File

@ -109,8 +109,8 @@ async def async_setup_entry(
def sonarr_exception_handler( def sonarr_exception_handler(
func: Callable[Concatenate[_T, _P], Awaitable[None]] # type: ignore[misc] func: Callable[Concatenate[_T, _P], Awaitable[None]]
) -> Callable[Concatenate[_T, _P], Coroutine[Any, Any, None]]: # type: ignore[misc] ) -> Callable[Concatenate[_T, _P], Coroutine[Any, Any, None]]:
"""Decorate Sonarr calls to handle Sonarr exceptions. """Decorate Sonarr calls to handle Sonarr exceptions.
A decorator that wraps the passed in function, catches Sonarr errors, A decorator that wraps the passed in function, catches Sonarr errors,

View File

@ -35,16 +35,14 @@ _P = ParamSpec("_P")
@overload @overload
def soco_error( def soco_error(
errorcodes: None = ..., errorcodes: None = ...,
) -> Callable[ # type: ignore[misc] ) -> Callable[[Callable[Concatenate[_T, _P], _R]], Callable[Concatenate[_T, _P], _R]]:
[Callable[Concatenate[_T, _P], _R]], Callable[Concatenate[_T, _P], _R]
]:
... ...
@overload @overload
def soco_error( def soco_error(
errorcodes: list[str], errorcodes: list[str],
) -> Callable[ # type: ignore[misc] ) -> Callable[
[Callable[Concatenate[_T, _P], _R]], Callable[Concatenate[_T, _P], _R | None] [Callable[Concatenate[_T, _P], _R]], Callable[Concatenate[_T, _P], _R | None]
]: ]:
... ...
@ -52,14 +50,14 @@ def soco_error(
def soco_error( def soco_error(
errorcodes: list[str] | None = None, errorcodes: list[str] | None = None,
) -> Callable[ # type: ignore[misc] ) -> Callable[
[Callable[Concatenate[_T, _P], _R]], Callable[Concatenate[_T, _P], _R | None] [Callable[Concatenate[_T, _P], _R]], Callable[Concatenate[_T, _P], _R | None]
]: ]:
"""Filter out specified UPnP errors and raise exceptions for service calls.""" """Filter out specified UPnP errors and raise exceptions for service calls."""
def decorator( def decorator(
funct: Callable[Concatenate[_T, _P], _R] # type: ignore[misc] funct: Callable[Concatenate[_T, _P], _R]
) -> Callable[Concatenate[_T, _P], _R | None]: # type: ignore[misc] ) -> Callable[Concatenate[_T, _P], _R | None]:
"""Decorate functions.""" """Decorate functions."""
def wrapper(self: _T, *args: _P.args, **kwargs: _P.kwargs) -> _R | None: def wrapper(self: _T, *args: _P.args, **kwargs: _P.kwargs) -> _R | None:

View File

@ -135,7 +135,7 @@ class SonosMedia:
self.title = track_info.get("title") self.title = track_info.get("title")
self.image_url = track_info.get("album_art") self.image_url = track_info.get("album_art")
playlist_position = int(track_info.get("playlist_position")) playlist_position = int(track_info.get("playlist_position", -1))
if playlist_position > 0: if playlist_position > 0:
self.queue_position = playlist_position self.queue_position = playlist_position

View File

@ -19,8 +19,8 @@ _P = ParamSpec("_P")
def async_refresh_after( def async_refresh_after(
func: Callable[Concatenate[_T, _P], Awaitable[None]] # type: ignore[misc] func: Callable[Concatenate[_T, _P], Awaitable[None]]
) -> Callable[Concatenate[_T, _P], Coroutine[Any, Any, None]]: # type: ignore[misc] ) -> Callable[Concatenate[_T, _P], Coroutine[Any, Any, None]]:
"""Define a wrapper to refresh after.""" """Define a wrapper to refresh after."""
async def _async_wrap(self: _T, *args: _P.args, **kwargs: _P.kwargs) -> None: async def _async_wrap(self: _T, *args: _P.args, **kwargs: _P.kwargs) -> None:

View File

@ -48,8 +48,8 @@ async def async_setup_entry(
def catch_vlc_errors( def catch_vlc_errors(
func: Callable[Concatenate[_T, _P], Awaitable[None]] # type: ignore[misc] func: Callable[Concatenate[_T, _P], Awaitable[None]]
) -> Callable[Concatenate[_T, _P], Coroutine[Any, Any, None]]: # type: ignore[misc] ) -> Callable[Concatenate[_T, _P], Coroutine[Any, Any, None]]:
"""Catch VLC errors.""" """Catch VLC errors."""
@wraps(func) @wraps(func)

View File

@ -108,7 +108,7 @@ async def async_handle_webhook(
if webhook["local_only"]: if webhook["local_only"]:
try: try:
remote = ip_address(request.remote) remote = ip_address(request.remote) # type: ignore[arg-type]
except ValueError: except ValueError:
_LOGGER.debug("Unable to parse remote ip %s", request.remote) _LOGGER.debug("Unable to parse remote ip %s", request.remote)
return Response(status=HTTPStatus.OK) return Response(status=HTTPStatus.OK)

View File

@ -87,8 +87,8 @@ _P = ParamSpec("_P")
def cmd( def cmd(
func: Callable[Concatenate[_T, _P], Awaitable[None]] # type: ignore[misc] func: Callable[Concatenate[_T, _P], Awaitable[None]]
) -> Callable[Concatenate[_T, _P], Coroutine[Any, Any, None]]: # type: ignore[misc] ) -> Callable[Concatenate[_T, _P], Coroutine[Any, Any, None]]:
"""Catch command exceptions.""" """Catch command exceptions."""
@wraps(func) @wraps(func)

View File

@ -90,7 +90,11 @@ def setup(hass: HomeAssistant, config: ConfigType) -> bool:
_LOGGER.error("HTTPError when connecting to Zabbix API: %s", http_error) _LOGGER.error("HTTPError when connecting to Zabbix API: %s", http_error)
zapi = None zapi = None
_LOGGER.error(RETRY_MESSAGE, http_error) _LOGGER.error(RETRY_MESSAGE, http_error)
event_helper.call_later(hass, RETRY_INTERVAL, lambda _: setup(hass, config)) event_helper.call_later(
hass,
RETRY_INTERVAL,
lambda _: setup(hass, config), # type: ignore[arg-type,return-value]
)
return True return True
hass.data[DOMAIN] = zapi hass.data[DOMAIN] = zapi

View File

@ -111,8 +111,8 @@ class TrackTemplateResult:
def threaded_listener_factory( def threaded_listener_factory(
async_factory: Callable[Concatenate[HomeAssistant, _P], Any] # type: ignore[misc] async_factory: Callable[Concatenate[HomeAssistant, _P], Any]
) -> Callable[Concatenate[HomeAssistant, _P], CALLBACK_TYPE]: # type: ignore[misc] ) -> Callable[Concatenate[HomeAssistant, _P], CALLBACK_TYPE]:
"""Convert an async event helper to a threaded one.""" """Convert an async event helper to a threaded one."""
@ft.wraps(async_factory) @ft.wraps(async_factory)

View File

@ -48,7 +48,7 @@ async def _async_process_single_integration_platform_component(
return return
try: try:
await integration_platform.process_platform(hass, component_name, platform) # type: ignore[misc,operator] # https://github.com/python/mypy/issues/5485 await integration_platform.process_platform(hass, component_name, platform)
except Exception: # pylint: disable=broad-except except Exception: # pylint: disable=broad-except
_LOGGER.exception( _LOGGER.exception(
"Error processing platform %s.%s", component_name, platform_name "Error processing platform %s.%s", component_name, platform_name

View File

@ -48,7 +48,7 @@ class RuntimeConfig:
open_ui: bool = False open_ui: bool = False
class HassEventLoopPolicy(asyncio.DefaultEventLoopPolicy): # type: ignore[valid-type,misc] class HassEventLoopPolicy(asyncio.DefaultEventLoopPolicy):
"""Event loop policy for Home Assistant.""" """Event loop policy for Home Assistant."""
def __init__(self, debug: bool) -> None: def __init__(self, debug: bool) -> None:
@ -59,7 +59,7 @@ class HassEventLoopPolicy(asyncio.DefaultEventLoopPolicy): # type: ignore[valid
@property @property
def loop_name(self) -> str: def loop_name(self) -> str:
"""Return name of the loop.""" """Return name of the loop."""
return self._loop_factory.__name__ # type: ignore[no-any-return] return self._loop_factory.__name__ # type: ignore[no-any-return,attr-defined]
def new_event_loop(self) -> asyncio.AbstractEventLoop: def new_event_loop(self) -> asyncio.AbstractEventLoop:
"""Get the event loop.""" """Get the event loop."""

View File

@ -13,6 +13,7 @@ warn_redundant_casts = true
warn_unused_configs = true warn_unused_configs = true
warn_unused_ignores = true warn_unused_ignores = true
enable_error_code = ignore-without-code enable_error_code = ignore-without-code
strict_concatenate = false
check_untyped_defs = true check_untyped_defs = true
disallow_incomplete_defs = true disallow_incomplete_defs = true
disallow_subclassing_any = true disallow_subclassing_any = true

View File

@ -11,7 +11,7 @@ codecov==2.1.12
coverage==6.3.2 coverage==6.3.2
freezegun==1.2.1 freezegun==1.2.1
mock-open==1.4.0 mock-open==1.4.0
mypy==0.942 mypy==0.950
pre-commit==2.17.0 pre-commit==2.17.0
pylint==2.13.7 pylint==2.13.7
pipdeptree==2.2.1 pipdeptree==2.2.1

View File

@ -221,6 +221,8 @@ GENERAL_SETTINGS: Final[dict[str, str]] = {
"warn_unused_configs": "true", "warn_unused_configs": "true",
"warn_unused_ignores": "true", "warn_unused_ignores": "true",
"enable_error_code": "ignore-without-code", "enable_error_code": "ignore-without-code",
# Strict_concatenate breaks passthrough ParamSpec typing
"strict_concatenate": "false",
} }
# This is basically the list of checks which is enabled for "strict=true". # This is basically the list of checks which is enabled for "strict=true".