From de72bbfaad441ba972c9bf9406b43e9f0757ed3a Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Fri, 5 Jan 2024 18:38:31 +0100 Subject: [PATCH] Enable strict typing for minecraft_server (#107262) --- .strict-typing | 1 + homeassistant/components/minecraft_server/api.py | 2 +- .../components/minecraft_server/config_flow.py | 15 ++++++++++++--- .../components/minecraft_server/sensor.py | 2 +- mypy.ini | 10 ++++++++++ 5 files changed, 25 insertions(+), 5 deletions(-) diff --git a/.strict-typing b/.strict-typing index db30bfb3494..e67ea8d60d8 100644 --- a/.strict-typing +++ b/.strict-typing @@ -263,6 +263,7 @@ homeassistant.components.media_source.* homeassistant.components.metoffice.* homeassistant.components.mikrotik.* homeassistant.components.min_max.* +homeassistant.components.minecraft_server.* homeassistant.components.mjpeg.* homeassistant.components.modbus.* homeassistant.components.modem_callerid.* diff --git a/homeassistant/components/minecraft_server/api.py b/homeassistant/components/minecraft_server/api.py index fc872d37bde..e44a02c9c78 100644 --- a/homeassistant/components/minecraft_server/api.py +++ b/homeassistant/components/minecraft_server/api.py @@ -128,7 +128,7 @@ class MinecraftServer: self, status_response: JavaStatusResponse ) -> MinecraftServerData: """Extract Java Edition server data out of status response.""" - players_list = [] + players_list: list[str] = [] if players := status_response.players.sample: for player in players: diff --git a/homeassistant/components/minecraft_server/config_flow.py b/homeassistant/components/minecraft_server/config_flow.py index 045133421fb..4f4c89fb0e6 100644 --- a/homeassistant/components/minecraft_server/config_flow.py +++ b/homeassistant/components/minecraft_server/config_flow.py @@ -1,5 +1,8 @@ """Config flow for Minecraft Server integration.""" +from __future__ import annotations + import logging +from typing import Any import voluptuous as vol @@ -20,9 +23,11 @@ class MinecraftServerConfigFlow(ConfigFlow, domain=DOMAIN): VERSION = 3 - async def async_step_user(self, user_input=None) -> FlowResult: + async def async_step_user( + self, user_input: dict[str, Any] | None = None + ) -> FlowResult: """Handle the initial step.""" - errors = {} + errors: dict[str, str] = {} if user_input: address = user_input[CONF_ADDRESS] @@ -57,7 +62,11 @@ class MinecraftServerConfigFlow(ConfigFlow, domain=DOMAIN): # form filled with user_input and eventually with errors otherwise). return self._show_config_form(user_input, errors) - def _show_config_form(self, user_input=None, errors=None) -> FlowResult: + def _show_config_form( + self, + user_input: dict[str, Any] | None = None, + errors: dict[str, str] | None = None, + ) -> FlowResult: """Show the setup form to the user.""" if user_input is None: user_input = {} diff --git a/homeassistant/components/minecraft_server/sensor.py b/homeassistant/components/minecraft_server/sensor.py index 671bbdb7a05..606d6085fda 100644 --- a/homeassistant/components/minecraft_server/sensor.py +++ b/homeassistant/components/minecraft_server/sensor.py @@ -61,7 +61,7 @@ def get_extra_state_attributes_players_list( data: MinecraftServerData, ) -> dict[str, list[str]]: """Return players list as extra state attributes, if available.""" - extra_state_attributes = {} + extra_state_attributes: dict[str, Any] = {} players_list = data.players_list if players_list is not None and len(players_list) != 0: diff --git a/mypy.ini b/mypy.ini index e5326bf16af..97927cf83aa 100644 --- a/mypy.ini +++ b/mypy.ini @@ -2391,6 +2391,16 @@ disallow_untyped_defs = true warn_return_any = true warn_unreachable = true +[mypy-homeassistant.components.minecraft_server.*] +check_untyped_defs = true +disallow_incomplete_defs = true +disallow_subclassing_any = true +disallow_untyped_calls = true +disallow_untyped_decorators = true +disallow_untyped_defs = true +warn_return_any = true +warn_unreachable = true + [mypy-homeassistant.components.mjpeg.*] check_untyped_defs = true disallow_incomplete_defs = true