Make mypy happy

This commit is contained in:
Joscha 2019-04-06 22:24:29 +00:00
parent 47a8014b4c
commit 500d91a14c
2 changed files with 26 additions and 10 deletions

View file

@ -1,6 +1,6 @@
import asyncio import asyncio
import logging import logging
from typing import Any, Awaitable, Callable from typing import Any, Awaitable, Callable, Dict, Optional
import websockets import websockets
@ -98,13 +98,14 @@ class Connection:
self._connected_condition = asyncio.Condition() self._connected_condition = asyncio.Condition()
self._disconnected_condition = asyncio.Condition() self._disconnected_condition = asyncio.Condition()
self._event_loop = None self._event_loop: Optional[asyncio.Task[None]] = None
# These must always be (re)set together. If one of them is None, all # These must always be (re)set together. If one of them is None, all
# must be None. # must be None.
self._ws = None self._ws = None
self._awaiting_replies = None self._awaiting_replies: Optional[Dict[str, Callable[...,
self._ping_check = None Awaitable[None]]]] = None
self._ping_check: Optional[asyncio.Task[None]] = None
def register_event(self, def register_event(self,
event: str, event: str,
@ -164,7 +165,7 @@ class Connection:
except websockets.InvalidStatusCode: except websockets.InvalidStatusCode:
return False return False
async def _disconnect_in(self, delay): async def _disconnect_in(self, delay: int) -> None:
await asyncio.sleep(delay) await asyncio.sleep(delay)
await self._disconnect() await self._disconnect()
@ -265,6 +266,8 @@ class Connection:
await self._disconnect() await self._disconnect()
# We know that _event_loop is not None, but this is to keep mypy happy.
if self._event_loop is not None:
await self._event_loop await self._event_loop
self._event_loop = None self._event_loop = None

View file

@ -1,6 +1,19 @@
__all__ = ["EuphException", "JoinException", "CouldNotConnectException", __all__ = [
"CouldNotAuthenticateException", "RoomClosedException", "EuphException",
"RateLimitException", "NotLoggedInException", "UnauthorizedException"] # Connection stuff
"IncorrectStateException",
"ConnectionClosedException",
# Joining a room
"JoinException",
"CouldNotConnectException",
"CouldNotAuthenticateException",
# Doing stuff in a room
"RoomClosedException",
# Other stuff
"RateLimitException",
"NotLoggedInException",
"UnauthorizedException",
]
class EuphException(Exception): class EuphException(Exception):
pass pass