Skip to content

Commit 6591ae6

Browse files
committed
Some mypy fixes
There is an mypy issue with NamedTuple relates to: python/mypy#3419
1 parent a4f68c0 commit 6591ae6

8 files changed

Lines changed: 26 additions & 17 deletions

File tree

‎bot/coroutine/logging.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ def log(file: str,
3333
async def _process_log() -> None:
3434
filename: str
3535
log: str
36-
file: IO[str]
3736
filename, log = _queue.popleft()
3837
async with aiofiles.open(filename, 'a', encoding='utf-8') as file:
3938
await file.write(log)

‎bot/data/__init__.py‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import socket
44
import source.ircmessage
55
import threading
6-
from bot.coroutine import connection, join
6+
from bot.coroutine import connection as connectionM
77
from collections import defaultdict, deque, OrderedDict
88
from datetime import datetime, timedelta
99
from typing import Any, Callable, Deque, Dict, Generic, Iterable, List
@@ -96,17 +96,17 @@ class Channel:
9696

9797
def __init__(self,
9898
channel: str,
99-
connection_: 'connection.ConnectionHandler',
99+
connection_: 'connectionM.ConnectionHandler',
100100
joinPriority: Union[int, float, str]=float('inf')) -> None:
101101
if not isinstance(channel, str):
102102
raise TypeError()
103-
if not isinstance(connection_, connection.ConnectionHandler):
103+
if not isinstance(connection_, connectionM.ConnectionHandler):
104104
raise TypeError()
105105
if not channel:
106106
raise ValueError()
107107
self._channel: str = channel
108108
self._ircChannel: str = '#' + channel
109-
self._connection: connection.ConnectionHandler = connection_
109+
self._connection: connectionM.ConnectionHandler = connection_
110110
self._isMod: bool = False
111111
self._isSubscriber: bool = False
112112
self._ircUsers: Set[str] = set()
@@ -135,7 +135,7 @@ def ircChannel(self) -> str:
135135
return self._ircChannel
136136

137137
@property
138-
def connection(self) -> 'connection.ConnectionHandler':
138+
def connection(self) -> 'connectionM.ConnectionHandler':
139139
return self._connection
140140

141141
@property

‎bot/utils.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ def joinChannel(broadcaster: str,
3434
t = min(bot.globals.channels[broadcaster].joinPriority, priority)
3535
bot.globals.channels[broadcaster].joinPriority = float(t)
3636
return False
37-
cluster: connection.ConnectionHandler = bot.globals.clusters[cluster]
38-
channel: data.Channel = data.Channel(broadcaster, cluster, priority)
37+
cluster_: connection.ConnectionHandler = bot.globals.clusters[cluster]
38+
channel: data.Channel = data.Channel(broadcaster, cluster_, priority)
3939
bot.globals.channels[broadcaster] = channel
40-
cluster.join_channel(channel)
40+
cluster_.join_channel(channel)
4141
return True
4242

4343

‎mypy.ini‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
[mypy]
2+
ignore_missing_imports = True

‎source/ircmessage.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
except ImportError:
1212
from .public.default import ircmessage # type: ignore
1313

14-
IrcHandler = Callable[['data.SocketHandler', IrcMessage, datetime], None]
14+
IrcHandler = Callable[['connection.ConnectionHandler', IrcMessage, datetime],
15+
None]
1516
ircHandlers: Dict[Union[str, int], IrcHandler] = {}
1617

1718
_logCommandPerChannel: List[str] = [

‎source/public/library/broadcaster.py‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import bot.config
1+
import asyncio
2+
import bot.config
23
import bot.globals
34
import time
45
from bot import utils
@@ -16,7 +17,8 @@ def come(database: DatabaseBase,
1617
send('Chat {channel} is banned from joining'.format(channel=channel))
1718
return True
1819
priority: Union[float, int] = database.getAutoJoinsPriority(channel)
19-
cluster: Optional[str] = twitch.chat_server(channel)
20+
cluster: Optional[str] = asyncio.get_event_loop().run_until_complete(
21+
twitch.chat_server(channel))
2022
joinResult: Optional[bool] = utils.joinChannel(channel, priority, cluster)
2123
if joinResult is None:
2224
send('Unable to join {channel} on a specified server according to '
@@ -75,7 +77,8 @@ def auto_join(database: DatabaseBase,
7577
def auto_join_add(database: DatabaseBase,
7678
channel: str,
7779
send: Send) -> bool:
78-
cluster: Optional[str] = twitch.chat_server(channel)
80+
cluster: Optional[str] = asyncio.get_event_loop().run_until_complete(
81+
twitch.chat_server(channel))
7982
if cluster is None:
8083
send('Auto join for {channel} failed due to Twitch '
8184
'error'.format(channel=channel))

‎source/public/library/channel.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import bot.config
1+
import asyncio
2+
import bot.config
23
import bot.globals
34
from bot import utils
45
from typing import Optional, Union
@@ -16,7 +17,8 @@ def join(database: DatabaseBase,
1617
return True
1718
priority: Union[int, float] = database.getAutoJoinsPriority(channel)
1819

19-
cluster: Optional[str] = twitch.chat_server(channel)
20+
cluster: Optional[str] = asyncio.get_event_loop().run_until_complete(
21+
twitch.chat_server(channel))
2022
if cluster not in bot.globals.clusters:
2123
send('Unknown chat server for ' + channel)
2224
elif utils.joinChannel(channel, priority, cluster):

‎source/public/manage/autojoin.py‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
from bot import utils
1+
import asyncio
2+
3+
from bot import utils
24
from contextlib import suppress
35
from typing import Optional
46
from ..library import broadcaster
@@ -54,7 +56,8 @@ def reload_server(database: DatabaseBase,
5456
send: Send) -> bool:
5557
autojoin: AutoJoinChannel
5658
for autojoin in database.getAutoJoinsChats():
57-
cluster: Optional[str] = twitch.chat_server(autojoin.broadcaster)
59+
cluster: Optional[str] = asyncio.get_event_loop().run_until_complete(
60+
twitch.chat_server(autojoin.broadcaster))
5861
if cluster is not None and autojoin.cluster != cluster:
5962
database.setAutoJoinServer(autojoin.broadcaster, cluster)
6063
utils.ensureServer(autojoin.broadcaster, autojoin.priority,

0 commit comments

Comments
 (0)