Skip to content

Commit 1a105e5

Browse files
Exireldgw
andauthored
Apply suggestions from code review (draft)
Co-authored-by: dgw <[email protected]>
1 parent f76d70d commit 1a105e5

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

sopel/irc/__init__.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
from typing import Any, Callable, Dict, Iterable, List, Optional, Set, Tuple, TYPE_CHECKING
3434

3535
from sopel import tools, trigger
36-
from sopel.tools import identifiers
36+
from sopel.tools.identifiers import Identifier
3737
from .abstract_backends import AbstractIRCBackend
3838
from .backends import AsyncioBackend
3939
from .isupport import ISupport
@@ -58,8 +58,7 @@ def __init__(self, settings: Config):
5858
self._name: str = settings.core.name
5959
self._isupport = ISupport()
6060
self._myinfo: Optional[MyInfo] = None
61-
self._nick: identifiers.Identifier = self.make_identifier(
62-
settings.core.nick)
61+
self._nick: Identifier = self.make_identifier(settings.core.nick)
6362

6463
self.backend: Optional[AbstractIRCBackend] = None
6564
"""IRC Connection Backend."""
@@ -76,13 +75,13 @@ def __init__(self, settings: Config):
7675
self.sending = threading.RLock()
7776
self.last_error_timestamp: Optional[datetime] = None
7877
self.error_count = 0
79-
self.stack: Dict[identifiers.Identifier, Dict[str, Any]] = {}
78+
self.stack: Dict[Identifier, Dict[str, Any]] = {}
8079
self.hasquit = False
8180
self.wantsrestart = False
8281
self.last_raw_line = '' # last raw line received
8382

8483
@property
85-
def nick(self) -> identifiers.Identifier:
84+
def nick(self) -> Identifier:
8685
"""Sopel's current nick.
8786
8887
Changing this while Sopel is running is unsupported.

sopel/irc/abstract_backends.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,9 @@ def run_forever(self) -> None:
5757
and it must call ``bot.on_connect`` once connected, or ``bot.on_close``
5858
if it fails to connect.
5959
60-
Then it must run forever, listening to the server, and allowing the
61-
bot to use :meth:`~.send_command` in a thread-safe way.
60+
Upon successful connection, it must run forever, listening to the
61+
server and allowing the bot to use :meth:`~.send_command` in a
62+
thread-safe way.
6263
"""
6364

6465
def decode_line(self, line: bytes) -> str:

sopel/irc/backends.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class AsyncioBackend(AbstractIRCBackend):
3737
"""IRC Backend implementation using :mod:`asyncio`.
3838
3939
:param bot: an instance of a bot that uses the backend
40-
:param host: hostname to connect to
40+
:param host: hostname/IP to connect to
4141
:param port: port to connect to
4242
:param source_address: optional source address as a tuple of
4343
``(host, port)``
@@ -128,7 +128,7 @@ def _ping_callback(self) -> None:
128128
self.send_ping(self._host)
129129

130130
def _timeout_callback(self) -> None:
131-
# cancel every other tasks
131+
# cancel other tasks
132132
for task in [self._ping_task, self._read_task]:
133133
if task is not None:
134134
task.cancel()
@@ -195,12 +195,12 @@ async def send(self, data: bytes) -> None:
195195
async def read_forever(self) -> None:
196196
"""Main reading loop of the backend.
197197
198-
This listens to the reader for IRC line, decodes the line, and pass
199-
that to
198+
This listens to the reader for an incoming IRC line, decodes the data,
199+
and passes it to
200200
:meth:`bot.on_message(data) <sopel.irc.AbstractBot.on_message>`, until
201201
the reader reaches the EOF (i.e. connection closed).
202202
203-
It manages timeout by scheduling two tasks:
203+
It manages connection timeouts by scheduling two tasks:
204204
205205
* a PING task, that will send a PING to the server as defined by
206206
the ping interval (from the configuration)
@@ -239,18 +239,18 @@ async def read_forever(self) -> None:
239239

240240
# connection is active: reset timeout tasks
241241
self._reset_timeout_tasks()
242-
# check content
243242

243+
# check content
244244
if not line:
245245
LOGGER.debug('No data received.')
246246
continue
247247

248-
# use bot's callback
248+
# use bot's callbacks
249249
data = self.decode_line(line)
250250
self.bot.log_raw(data, '<<')
251251
self.bot.on_message(data)
252252

253-
# cancel timeout tasks
253+
# cancel timeout tasks when reading loop ends
254254
self._cancel_timeout_tasks()
255255

256256
# run & connection
@@ -286,7 +286,7 @@ def get_connection_kwargs(self) -> Dict:
286286
async def _run_forever(self) -> None:
287287
self._loop = asyncio.get_running_loop()
288288

289-
# register signals handlers
289+
# register signal handlers
290290
for quit_signal in QUIT_SIGNALS:
291291
self._loop.add_signal_handler(quit_signal, self._signal_quit)
292292
for restart_signal in RESTART_SIGNALS:

0 commit comments

Comments
 (0)