From 3a192896df9e85968bb65d80b321d485013c284e Mon Sep 17 00:00:00 2001 From: Ruslan Sayfutdinov Date: Mon, 10 May 2021 13:20:25 +0100 Subject: [PATCH] Enable some strict mypy checks globally (#50398) * Enable some strict mypy checks globally * Update mypy.ini --- homeassistant/components/dyson/fan.py | 2 +- mypy.ini | 104 +------------------------- script/hassfest/mypy_config.py | 5 +- 3 files changed, 6 insertions(+), 105 deletions(-) diff --git a/homeassistant/components/dyson/fan.py b/homeassistant/components/dyson/fan.py index 5b24b4a9df7..38b4b511df4 100644 --- a/homeassistant/components/dyson/fan.py +++ b/homeassistant/components/dyson/fan.py @@ -234,7 +234,7 @@ class DysonFanEntity(DysonEntity, FanEntity): """Set the exact speed of the fan.""" raise NotImplementedError - def service_set_dyson_speed(self, dyson_speed: str) -> None: + def service_set_dyson_speed(self, dyson_speed: int) -> None: """Handle the service to set dyson speed.""" if dyson_speed not in SPEED_LIST_DYSON: raise ValueError(f'"{dyson_speed}" is not a valid Dyson speed') diff --git a/mypy.ini b/mypy.ini index ef86441ef4d..65d626cbf8d 100644 --- a/mypy.ini +++ b/mypy.ini @@ -7,9 +7,11 @@ python_version = 3.8 show_error_codes = true follow_imports = silent ignore_missing_imports = true +strict_equality = true warn_incomplete_stub = true warn_redundant_casts = true warn_unused_configs = true +warn_unused_ignores = true check_untyped_defs = true disallow_incomplete_defs = true disallow_subclassing_any = true @@ -17,10 +19,8 @@ disallow_untyped_calls = true disallow_untyped_decorators = true disallow_untyped_defs = true no_implicit_optional = true -strict_equality = true warn_return_any = true warn_unreachable = true -warn_unused_ignores = true [mypy-homeassistant.components.*] check_untyped_defs = false @@ -30,10 +30,8 @@ disallow_untyped_calls = false disallow_untyped_decorators = false disallow_untyped_defs = false no_implicit_optional = false -strict_equality = false warn_return_any = false warn_unreachable = false -warn_unused_ignores = false [mypy-homeassistant.components] check_untyped_defs = true @@ -43,10 +41,8 @@ disallow_untyped_calls = true disallow_untyped_decorators = true disallow_untyped_defs = true no_implicit_optional = true -strict_equality = true warn_return_any = true warn_unreachable = true -warn_unused_ignores = true [mypy-homeassistant.components.airly.*] check_untyped_defs = true @@ -56,10 +52,8 @@ disallow_untyped_calls = true disallow_untyped_decorators = true disallow_untyped_defs = true no_implicit_optional = true -strict_equality = true warn_return_any = true warn_unreachable = true -warn_unused_ignores = true [mypy-homeassistant.components.automation.*] check_untyped_defs = true @@ -69,10 +63,8 @@ disallow_untyped_calls = true disallow_untyped_decorators = true disallow_untyped_defs = true no_implicit_optional = true -strict_equality = true warn_return_any = true warn_unreachable = true -warn_unused_ignores = true [mypy-homeassistant.components.binary_sensor.*] check_untyped_defs = true @@ -82,10 +74,8 @@ disallow_untyped_calls = true disallow_untyped_decorators = true disallow_untyped_defs = true no_implicit_optional = true -strict_equality = true warn_return_any = true warn_unreachable = true -warn_unused_ignores = true [mypy-homeassistant.components.bond.*] check_untyped_defs = true @@ -95,10 +85,8 @@ disallow_untyped_calls = true disallow_untyped_decorators = true disallow_untyped_defs = true no_implicit_optional = true -strict_equality = true warn_return_any = true warn_unreachable = true -warn_unused_ignores = true [mypy-homeassistant.components.brother.*] check_untyped_defs = true @@ -108,10 +96,8 @@ disallow_untyped_calls = true disallow_untyped_decorators = true disallow_untyped_defs = true no_implicit_optional = true -strict_equality = true warn_return_any = true warn_unreachable = true -warn_unused_ignores = true [mypy-homeassistant.components.calendar.*] check_untyped_defs = true @@ -121,10 +107,8 @@ disallow_untyped_calls = true disallow_untyped_decorators = true disallow_untyped_defs = true no_implicit_optional = true -strict_equality = true warn_return_any = true warn_unreachable = true -warn_unused_ignores = true [mypy-homeassistant.components.cover.*] check_untyped_defs = true @@ -134,10 +118,8 @@ disallow_untyped_calls = true disallow_untyped_decorators = true disallow_untyped_defs = true no_implicit_optional = true -strict_equality = true warn_return_any = true warn_unreachable = true -warn_unused_ignores = true [mypy-homeassistant.components.device_automation.*] check_untyped_defs = true @@ -147,10 +129,8 @@ disallow_untyped_calls = true disallow_untyped_decorators = true disallow_untyped_defs = true no_implicit_optional = true -strict_equality = true warn_return_any = true warn_unreachable = true -warn_unused_ignores = true [mypy-homeassistant.components.elgato.*] check_untyped_defs = true @@ -160,10 +140,8 @@ disallow_untyped_calls = true disallow_untyped_decorators = true disallow_untyped_defs = true no_implicit_optional = true -strict_equality = true warn_return_any = true warn_unreachable = true -warn_unused_ignores = true [mypy-homeassistant.components.frontend.*] check_untyped_defs = true @@ -173,10 +151,8 @@ disallow_untyped_calls = true disallow_untyped_decorators = true disallow_untyped_defs = true no_implicit_optional = true -strict_equality = true warn_return_any = true warn_unreachable = true -warn_unused_ignores = true [mypy-homeassistant.components.geo_location.*] check_untyped_defs = true @@ -186,10 +162,8 @@ disallow_untyped_calls = true disallow_untyped_decorators = true disallow_untyped_defs = true no_implicit_optional = true -strict_equality = true warn_return_any = true warn_unreachable = true -warn_unused_ignores = true [mypy-homeassistant.components.group.*] check_untyped_defs = true @@ -199,10 +173,8 @@ disallow_untyped_calls = true disallow_untyped_decorators = true disallow_untyped_defs = true no_implicit_optional = true -strict_equality = true warn_return_any = true warn_unreachable = true -warn_unused_ignores = true [mypy-homeassistant.components.history.*] check_untyped_defs = true @@ -212,10 +184,8 @@ disallow_untyped_calls = true disallow_untyped_decorators = true disallow_untyped_defs = true no_implicit_optional = true -strict_equality = true warn_return_any = true warn_unreachable = true -warn_unused_ignores = true [mypy-homeassistant.components.http.*] check_untyped_defs = true @@ -225,10 +195,8 @@ disallow_untyped_calls = true disallow_untyped_decorators = true disallow_untyped_defs = true no_implicit_optional = true -strict_equality = true warn_return_any = true warn_unreachable = true -warn_unused_ignores = true [mypy-homeassistant.components.huawei_lte.*] check_untyped_defs = true @@ -238,10 +206,8 @@ disallow_untyped_calls = true disallow_untyped_decorators = true disallow_untyped_defs = true no_implicit_optional = true -strict_equality = true warn_return_any = true warn_unreachable = true -warn_unused_ignores = true [mypy-homeassistant.components.hyperion.*] check_untyped_defs = true @@ -251,10 +217,8 @@ disallow_untyped_calls = true disallow_untyped_decorators = true disallow_untyped_defs = true no_implicit_optional = true -strict_equality = true warn_return_any = true warn_unreachable = true -warn_unused_ignores = true [mypy-homeassistant.components.image_processing.*] check_untyped_defs = true @@ -264,10 +228,8 @@ disallow_untyped_calls = true disallow_untyped_decorators = true disallow_untyped_defs = true no_implicit_optional = true -strict_equality = true warn_return_any = true warn_unreachable = true -warn_unused_ignores = true [mypy-homeassistant.components.integration.*] check_untyped_defs = true @@ -277,10 +239,8 @@ disallow_untyped_calls = true disallow_untyped_decorators = true disallow_untyped_defs = true no_implicit_optional = true -strict_equality = true warn_return_any = true warn_unreachable = true -warn_unused_ignores = true [mypy-homeassistant.components.knx.*] check_untyped_defs = true @@ -290,10 +250,8 @@ disallow_untyped_calls = true disallow_untyped_decorators = true disallow_untyped_defs = true no_implicit_optional = true -strict_equality = true warn_return_any = true warn_unreachable = true -warn_unused_ignores = true [mypy-homeassistant.components.light.*] check_untyped_defs = true @@ -303,10 +261,8 @@ disallow_untyped_calls = true disallow_untyped_decorators = true disallow_untyped_defs = true no_implicit_optional = true -strict_equality = true warn_return_any = true warn_unreachable = true -warn_unused_ignores = true [mypy-homeassistant.components.lock.*] check_untyped_defs = true @@ -316,10 +272,8 @@ disallow_untyped_calls = true disallow_untyped_decorators = true disallow_untyped_defs = true no_implicit_optional = true -strict_equality = true warn_return_any = true warn_unreachable = true -warn_unused_ignores = true [mypy-homeassistant.components.mailbox.*] check_untyped_defs = true @@ -329,10 +283,8 @@ disallow_untyped_calls = true disallow_untyped_decorators = true disallow_untyped_defs = true no_implicit_optional = true -strict_equality = true warn_return_any = true warn_unreachable = true -warn_unused_ignores = true [mypy-homeassistant.components.media_player.*] check_untyped_defs = true @@ -342,10 +294,8 @@ disallow_untyped_calls = true disallow_untyped_decorators = true disallow_untyped_defs = true no_implicit_optional = true -strict_equality = true warn_return_any = true warn_unreachable = true -warn_unused_ignores = true [mypy-homeassistant.components.nam.*] check_untyped_defs = true @@ -355,10 +305,8 @@ disallow_untyped_calls = true disallow_untyped_decorators = true disallow_untyped_defs = true no_implicit_optional = true -strict_equality = true warn_return_any = true warn_unreachable = true -warn_unused_ignores = true [mypy-homeassistant.components.notify.*] check_untyped_defs = true @@ -368,10 +316,8 @@ disallow_untyped_calls = true disallow_untyped_decorators = true disallow_untyped_defs = true no_implicit_optional = true -strict_equality = true warn_return_any = true warn_unreachable = true -warn_unused_ignores = true [mypy-homeassistant.components.number.*] check_untyped_defs = true @@ -381,10 +327,8 @@ disallow_untyped_calls = true disallow_untyped_decorators = true disallow_untyped_defs = true no_implicit_optional = true -strict_equality = true warn_return_any = true warn_unreachable = true -warn_unused_ignores = true [mypy-homeassistant.components.persistent_notification.*] check_untyped_defs = true @@ -394,10 +338,8 @@ disallow_untyped_calls = true disallow_untyped_decorators = true disallow_untyped_defs = true no_implicit_optional = true -strict_equality = true warn_return_any = true warn_unreachable = true -warn_unused_ignores = true [mypy-homeassistant.components.proximity.*] check_untyped_defs = true @@ -407,10 +349,8 @@ disallow_untyped_calls = true disallow_untyped_decorators = true disallow_untyped_defs = true no_implicit_optional = true -strict_equality = true warn_return_any = true warn_unreachable = true -warn_unused_ignores = true [mypy-homeassistant.components.recorder.purge] check_untyped_defs = true @@ -420,10 +360,8 @@ disallow_untyped_calls = true disallow_untyped_decorators = true disallow_untyped_defs = true no_implicit_optional = true -strict_equality = true warn_return_any = true warn_unreachable = true -warn_unused_ignores = true [mypy-homeassistant.components.recorder.repack] check_untyped_defs = true @@ -433,10 +371,8 @@ disallow_untyped_calls = true disallow_untyped_decorators = true disallow_untyped_defs = true no_implicit_optional = true -strict_equality = true warn_return_any = true warn_unreachable = true -warn_unused_ignores = true [mypy-homeassistant.components.remote.*] check_untyped_defs = true @@ -446,10 +382,8 @@ disallow_untyped_calls = true disallow_untyped_decorators = true disallow_untyped_defs = true no_implicit_optional = true -strict_equality = true warn_return_any = true warn_unreachable = true -warn_unused_ignores = true [mypy-homeassistant.components.scene.*] check_untyped_defs = true @@ -459,10 +393,8 @@ disallow_untyped_calls = true disallow_untyped_decorators = true disallow_untyped_defs = true no_implicit_optional = true -strict_equality = true warn_return_any = true warn_unreachable = true -warn_unused_ignores = true [mypy-homeassistant.components.sensor.*] check_untyped_defs = true @@ -472,10 +404,8 @@ disallow_untyped_calls = true disallow_untyped_decorators = true disallow_untyped_defs = true no_implicit_optional = true -strict_equality = true warn_return_any = true warn_unreachable = true -warn_unused_ignores = true [mypy-homeassistant.components.slack.*] check_untyped_defs = true @@ -485,10 +415,8 @@ disallow_untyped_calls = true disallow_untyped_decorators = true disallow_untyped_defs = true no_implicit_optional = true -strict_equality = true warn_return_any = true warn_unreachable = true -warn_unused_ignores = true [mypy-homeassistant.components.sonos.media_player] check_untyped_defs = true @@ -498,10 +426,8 @@ disallow_untyped_calls = true disallow_untyped_decorators = true disallow_untyped_defs = true no_implicit_optional = true -strict_equality = true warn_return_any = true warn_unreachable = true -warn_unused_ignores = true [mypy-homeassistant.components.sun.*] check_untyped_defs = true @@ -511,10 +437,8 @@ disallow_untyped_calls = true disallow_untyped_decorators = true disallow_untyped_defs = true no_implicit_optional = true -strict_equality = true warn_return_any = true warn_unreachable = true -warn_unused_ignores = true [mypy-homeassistant.components.switch.*] check_untyped_defs = true @@ -524,10 +448,8 @@ disallow_untyped_calls = true disallow_untyped_decorators = true disallow_untyped_defs = true no_implicit_optional = true -strict_equality = true warn_return_any = true warn_unreachable = true -warn_unused_ignores = true [mypy-homeassistant.components.synology_dsm.*] check_untyped_defs = true @@ -537,10 +459,8 @@ disallow_untyped_calls = true disallow_untyped_decorators = true disallow_untyped_defs = true no_implicit_optional = true -strict_equality = true warn_return_any = true warn_unreachable = true -warn_unused_ignores = true [mypy-homeassistant.components.systemmonitor.*] check_untyped_defs = true @@ -550,10 +470,8 @@ disallow_untyped_calls = true disallow_untyped_decorators = true disallow_untyped_defs = true no_implicit_optional = true -strict_equality = true warn_return_any = true warn_unreachable = true -warn_unused_ignores = true [mypy-homeassistant.components.tts.*] check_untyped_defs = true @@ -563,10 +481,8 @@ disallow_untyped_calls = true disallow_untyped_decorators = true disallow_untyped_defs = true no_implicit_optional = true -strict_equality = true warn_return_any = true warn_unreachable = true -warn_unused_ignores = true [mypy-homeassistant.components.vacuum.*] check_untyped_defs = true @@ -576,10 +492,8 @@ disallow_untyped_calls = true disallow_untyped_decorators = true disallow_untyped_defs = true no_implicit_optional = true -strict_equality = true warn_return_any = true warn_unreachable = true -warn_unused_ignores = true [mypy-homeassistant.components.water_heater.*] check_untyped_defs = true @@ -589,10 +503,8 @@ disallow_untyped_calls = true disallow_untyped_decorators = true disallow_untyped_defs = true no_implicit_optional = true -strict_equality = true warn_return_any = true warn_unreachable = true -warn_unused_ignores = true [mypy-homeassistant.components.weather.*] check_untyped_defs = true @@ -602,10 +514,8 @@ disallow_untyped_calls = true disallow_untyped_decorators = true disallow_untyped_defs = true no_implicit_optional = true -strict_equality = true warn_return_any = true warn_unreachable = true -warn_unused_ignores = true [mypy-homeassistant.components.websocket_api.*] check_untyped_defs = true @@ -615,10 +525,8 @@ disallow_untyped_calls = true disallow_untyped_decorators = true disallow_untyped_defs = true no_implicit_optional = true -strict_equality = true warn_return_any = true warn_unreachable = true -warn_unused_ignores = true [mypy-homeassistant.components.zeroconf.*] check_untyped_defs = true @@ -628,10 +536,8 @@ disallow_untyped_calls = true disallow_untyped_decorators = true disallow_untyped_defs = true no_implicit_optional = true -strict_equality = true warn_return_any = true warn_unreachable = true -warn_unused_ignores = true [mypy-homeassistant.components.zone.*] check_untyped_defs = true @@ -641,10 +547,8 @@ disallow_untyped_calls = true disallow_untyped_decorators = true disallow_untyped_defs = true no_implicit_optional = true -strict_equality = true warn_return_any = true warn_unreachable = true -warn_unused_ignores = true [mypy-homeassistant.components.zwave_js.*] check_untyped_defs = true @@ -654,10 +558,8 @@ disallow_untyped_calls = true disallow_untyped_decorators = true disallow_untyped_defs = true no_implicit_optional = true -strict_equality = true warn_return_any = true warn_unreachable = true -warn_unused_ignores = true [mypy-tests.*] check_untyped_defs = false @@ -667,10 +569,8 @@ disallow_untyped_calls = false disallow_untyped_decorators = false disallow_untyped_defs = false no_implicit_optional = false -strict_equality = false warn_return_any = false warn_unreachable = false -warn_unused_ignores = false [mypy-homeassistant.components.adguard.*] ignore_errors = true diff --git a/script/hassfest/mypy_config.py b/script/hassfest/mypy_config.py index a810e4baf98..54e5b5b13a7 100644 --- a/script/hassfest/mypy_config.py +++ b/script/hassfest/mypy_config.py @@ -256,10 +256,13 @@ GENERAL_SETTINGS: Final[dict[str, str]] = { "python_version": "3.8", "show_error_codes": "true", "follow_imports": "silent", + # Enable some checks globally. "ignore_missing_imports": "true", + "strict_equality": "true", "warn_incomplete_stub": "true", "warn_redundant_casts": "true", "warn_unused_configs": "true", + "warn_unused_ignores": "true", } # This is basically the list of checks which is enabled for "strict=true". @@ -272,10 +275,8 @@ STRICT_SETTINGS: Final[list[str]] = [ "disallow_untyped_decorators", "disallow_untyped_defs", "no_implicit_optional", - "strict_equality", "warn_return_any", "warn_unreachable", - "warn_unused_ignores", # TODO: turn these on, address issues # "disallow_any_generics", # "no_implicit_reexport",