Skip to content

Commit

Permalink
Enable strict typing for api (home-assistant#108363)
Browse files Browse the repository at this point in the history
  • Loading branch information
cdce8p authored Jan 19, 2024
1 parent 7e0e306 commit 15bd31e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions .strict-typing
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand Down
10 changes: 10 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 15bd31e

Please sign in to comment.