Skip to content

Commit

Permalink
irc: begin migrating Optional[type] to type | None
Browse files Browse the repository at this point in the history
Might as well migrate as we touch things. I just updated some docstring
stuff in `irc/__init__.py`, and as long as I'm in the file let's get rid
of the `typing.Optional` import, too.
  • Loading branch information
dgw committed Nov 11, 2024
1 parent bad8860 commit 0b85704
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions sopel/irc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import time
from typing import (
Any,
Optional,
TYPE_CHECKING,
)

Expand Down Expand Up @@ -71,7 +70,7 @@ def __init__(self, settings: Config):
self._name: str = settings.core.name
self._isupport = ISupport()
self._capabilities = Capabilities()
self._myinfo: Optional[MyInfo] = None
self._myinfo: MyInfo | None = None
self._nick: identifiers.Identifier = self.make_identifier(
settings.core.nick)

Expand All @@ -87,7 +86,7 @@ def __init__(self, settings: Config):

# internal machinery
self.sending = threading.RLock()
self.last_error_timestamp: Optional[datetime] = None
self.last_error_timestamp: datetime | None = None
self.error_count = 0
self.stack: dict[identifiers.Identifier, dict[str, Any]] = {}
self.hasquit = False
Expand Down Expand Up @@ -180,7 +179,7 @@ def enabled_capabilities(self) -> set[str]:
warning_in='8.1',
removed_in='9.0',
)
def server_capabilities(self) -> dict[str, Optional[str]]:
def server_capabilities(self) -> dict[str, str | None]:
"""A dict mapping supported IRCv3 capabilities to their options.
For example, if the server specifies the capability ``sasl=EXTERNAL``,
Expand Down Expand Up @@ -225,7 +224,7 @@ def myinfo(self) -> MyInfo:

@property
@abc.abstractmethod
def hostmask(self) -> Optional[str]:
def hostmask(self) -> str | None:
"""The bot's hostmask."""

# Utility
Expand Down Expand Up @@ -343,7 +342,7 @@ def get_irc_backend(
self,
host: str,
port: int,
source_address: Optional[tuple[str, int]],
source_address: tuple[str, int] | None,
) -> AbstractIRCBackend:
"""Set up the IRC backend based on the bot's settings.
Expand Down Expand Up @@ -579,7 +578,7 @@ def log_raw(self, line: str, prefix: str) -> None:
logger = logging.getLogger('sopel.raw')
logger.info("%s\t%r", prefix, line)

def write(self, args: Iterable[str], text: Optional[str] = None) -> None:
def write(self, args: Iterable[str], text: str | None = None) -> None:
"""Send a command to the server.
:param args: an iterable of strings, which will be joined by spaces
Expand Down Expand Up @@ -626,7 +625,7 @@ def action(self, text: str, dest: str) -> None:
"""
self.say('\001ACTION {}\001'.format(text), dest)

def join(self, channel: str, password: Optional[str] = None) -> None:
def join(self, channel: str, password: str | None = None) -> None:
"""Join a ``channel``.
:param channel: the channel to join
Expand All @@ -646,7 +645,7 @@ def kick(
self,
nick: str,
channel: str,
text: Optional[str] = None,
text: str | None = None,
) -> None:
"""Kick a ``nick`` from a ``channel``.
Expand Down Expand Up @@ -674,7 +673,7 @@ def notice(self, text: str, dest: str) -> None:

self.backend.send_notice(dest, text)

def part(self, channel: str, msg: Optional[str] = None) -> None:
def part(self, channel: str, msg: str | None = None) -> None:
"""Leave a channel.
:param channel: the channel to leave
Expand All @@ -685,7 +684,7 @@ def part(self, channel: str, msg: Optional[str] = None) -> None:

self.backend.send_part(channel, reason=msg)

def quit(self, message: Optional[str] = None) -> None:
def quit(self, message: str | None = None) -> None:
"""Disconnect from IRC and close the bot.
:param message: optional QUIT message to send (e.g. "Bye!")
Expand All @@ -704,7 +703,7 @@ def quit(self, message: Optional[str] = None) -> None:
# problematic because whomever called quit might still want to do
# something before the main thread quits.

def restart(self, message: Optional[str] = None) -> None:
def restart(self, message: str | None = None) -> None:
"""Disconnect from IRC and restart the bot.
:param message: optional QUIT message to send (e.g. "Be right back!")
Expand Down

0 comments on commit 0b85704

Please sign in to comment.