diff --git a/api/async_bot.py b/api/async_bot.py index 5a8afba..981e296 100644 --- a/api/async_bot.py +++ b/api/async_bot.py @@ -6,6 +6,7 @@ Asyncio wrapper for AsyncOperator methods. import asyncio from contextlib import contextmanager +import typing as T from bot_z.async_operator import AsyncOperator from bot_z.exceptions import OperationFailed @@ -19,14 +20,14 @@ def this_loop(loop): asyncio.set_event_loop(_loop) -def init(base_url: str, name: str) -> AsyncOperator: +def init(base_url: T.Text, name: T.Text) -> AsyncOperator: """ Initialize the stateful object. """ return AsyncOperator(base_url, name) -async def login(op: AsyncOperator, username: str, password: str) -> bool: +async def login(op: AsyncOperator, username: T.Text, password: T.Text) -> bool: """ Executes the login asynchronously and returns the AsyncOperator object. diff --git a/api/rest.py b/api/rest.py index e4caff9..a1a4521 100644 --- a/api/rest.py +++ b/api/rest.py @@ -17,12 +17,12 @@ from api import BASE_URI alog = logging.getLogger("api") routes = web.RouteTableDef() -OPERATORS = {} +OPERATORS = {} # type: T.Dict[T.Text, AsyncOperator] async def get_set_operator( request: web.Request, user: T.Text, password: T.Text -) -> AsyncOperator: +) -> T.Tuple[AsyncOperator, Session]: session = await get_session(request) if "async_operator" in session: op = OPERATORS[session["async_operator"]] diff --git a/bot_z/async_operator.py b/bot_z/async_operator.py index 5d2f95b..a037672 100644 --- a/bot_z/async_operator.py +++ b/bot_z/async_operator.py @@ -10,6 +10,7 @@ import asyncio from concurrent.futures import ThreadPoolExecutor import functools import logging +import typing as T from bot_z.operator import Operator from bot_z.exceptions import OperationFailed @@ -18,7 +19,13 @@ from bot_z.exceptions import OperationFailed alog = logging.getLogger("asyncio") -async def _push_to_loop(loop, executor, func, *args, **kwargs): +async def _push_to_loop( + loop: asyncio.AbstractEventLoop, + executor: ThreadPoolExecutor, + func: T.Callable, + *args, + **kwargs +) -> T.Any: sync_task = [ loop.run_in_executor(executor, functools.partial(func, **kwargs), *args) ] diff --git a/bot_z/operator.py b/bot_z/operator.py index 2e4efcd..4d4f497 100644 --- a/bot_z/operator.py +++ b/bot_z/operator.py @@ -277,7 +277,7 @@ class Operator(wd.Firefox): except NoSuchElementException: pass - def get_movements(self) -> T.List[T.Tuple[T.Text]]: + def get_movements(self) -> T.List[T.Optional[T.Tuple[T.Text, T.Text]]]: self._switch_to_container() try: result = [] # type: T.List[T.Tuple[T.Text]] @@ -286,7 +286,9 @@ class Operator(wd.Firefox): ) for row in movements_table: data = row.text.strip().split("\n") # type: T.List[T.Text] - result.append(tuple(i.strip() for i in data if i.strip())) # noqa + result.append( # type: ignore + tuple(i.strip() for i in data if i.strip()) + ) except NoSuchElementException: return [] return result