mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
Make typing checks more strict (#14429)
## Description: Make typing checks more strict: add `--strict-optional` flag that forbids implicit None return type. This flag will become default in the next version of mypy (0.600) Add `homeassistant/util/` to checked dirs. ## Checklist: - [x] The code change is tested and works locally. - [x] Local tests pass with `tox`. **Your PR cannot be merged unless tests pass**
This commit is contained in:
@@ -17,7 +17,8 @@ import threading
|
||||
from time import monotonic
|
||||
|
||||
from types import MappingProxyType
|
||||
from typing import Optional, Any, Callable, List, TypeVar, Dict # NOQA
|
||||
from typing import ( # NOQA
|
||||
Optional, Any, Callable, List, TypeVar, Dict, Coroutine)
|
||||
|
||||
from async_timeout import timeout
|
||||
import voluptuous as vol
|
||||
@@ -205,8 +206,8 @@ class HomeAssistant(object):
|
||||
def async_add_job(
|
||||
self,
|
||||
target: Callable[..., Any],
|
||||
*args: Any) -> Optional[asyncio.tasks.Task]:
|
||||
"""Add a job from within the eventloop.
|
||||
*args: Any) -> Optional[asyncio.Future]:
|
||||
"""Add a job from within the event loop.
|
||||
|
||||
This method must be run in the event loop.
|
||||
|
||||
@@ -230,11 +231,26 @@ class HomeAssistant(object):
|
||||
|
||||
return task
|
||||
|
||||
@callback
|
||||
def async_create_task(self, target: Coroutine) -> asyncio.tasks.Task:
|
||||
"""Create a task from within the eventloop.
|
||||
|
||||
This method must be run in the event loop.
|
||||
|
||||
target: target to call.
|
||||
"""
|
||||
task = self.loop.create_task(target)
|
||||
|
||||
if self._track_task:
|
||||
self._pending_tasks.append(task)
|
||||
|
||||
return task
|
||||
|
||||
@callback
|
||||
def async_add_executor_job(
|
||||
self,
|
||||
target: Callable[..., Any],
|
||||
*args: Any) -> asyncio.tasks.Task:
|
||||
*args: Any) -> asyncio.Future:
|
||||
"""Add an executor job from within the event loop."""
|
||||
task = self.loop.run_in_executor(None, target, *args)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user