From 15bd31e8d845139b001e10f7b288e6480c0847fe Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Fri, 19 Jan 2024 13:33:20 +0100 Subject: [PATCH] Enable strict typing for api (#108363) --- .strict-typing | 1 + homeassistant/components/api/__init__.py | 4 ++-- mypy.ini | 10 ++++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/.strict-typing b/.strict-typing index 9ab2d535f0fac..a7758750d5e9e 100644 --- a/.strict-typing +++ b/.strict-typing @@ -77,6 +77,7 @@ homeassistant.components.anova.* homeassistant.components.anthemav.* homeassistant.components.apache_kafka.* homeassistant.components.apcupsd.* +homeassistant.components.api.* homeassistant.components.apprise.* homeassistant.components.aprs.* homeassistant.components.aqualogic.* diff --git a/homeassistant/components/api/__init__.py b/homeassistant/components/api/__init__.py index 8a5e1f0b0e0d1..048837dae6804 100644 --- a/homeassistant/components/api/__init__.py +++ b/homeassistant/components/api/__init__.py @@ -433,7 +433,7 @@ def get(self, request: web.Request) -> web.Response: @lru_cache -def _cached_template(template_str: str, hass: ha.HomeAssistant) -> template.Template: +def _cached_template(template_str: str, hass: HomeAssistant) -> template.Template: """Return a cached template.""" return template.Template(template_str, hass) @@ -450,7 +450,7 @@ async def post(self, request: web.Request) -> web.Response: try: data = await request.json() tpl = _cached_template(data["template"], request.app["hass"]) - return tpl.async_render(variables=data.get("variables"), parse_result=False) + return tpl.async_render(variables=data.get("variables"), parse_result=False) # type: ignore[no-any-return] except (ValueError, TemplateError) as ex: return self.json_message( f"Error rendering template: {ex}", HTTPStatus.BAD_REQUEST diff --git a/mypy.ini b/mypy.ini index bfeaa28ef0413..163be50e6eb0c 100644 --- a/mypy.ini +++ b/mypy.ini @@ -530,6 +530,16 @@ disallow_untyped_defs = true warn_return_any = true warn_unreachable = true +[mypy-homeassistant.components.api.*] +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.apprise.*] check_untyped_defs = true disallow_incomplete_defs = true