aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar jesopo2018-10-31 15:12:46 +0000
committerGravatar jesopo2018-10-31 15:12:46 +0000
commita4d8d1f85557ced37ab41038e9fbd25d6332eebf (patch)
treeee2886a839a32ac54cd64a0447044af6a19f7d08
parentMove setting BitBotFormatter's converter (to time.gmtime) to class definition as (diff)
signature
Fix some non-explicit None returns, add type hints to important variables
-rw-r--r--src/Config.py2
-rw-r--r--src/IRCBot.py1
-rw-r--r--src/IRCBuffer.py2
-rw-r--r--src/IRCServer.py30
-rw-r--r--src/IRCUser.py2
-rw-r--r--src/utils/__init__.py3
6 files changed, 23 insertions, 17 deletions
diff --git a/src/Config.py b/src/Config.py
index dacb14dd..57fc9b0e 100644
--- a/src/Config.py
+++ b/src/Config.py
@@ -3,7 +3,7 @@ import configparser, os, typing
class Config(object):
def __init__(self, location: str):
self.location = location
- self._config = {}
+ self._config = {} # type: typing.Dict[str, str]
self.load()
def load(self):
diff --git a/src/IRCBot.py b/src/IRCBot.py
index e1683f97..e67dc0ee 100644
--- a/src/IRCBot.py
+++ b/src/IRCBot.py
@@ -62,6 +62,7 @@ class Bot(object):
for server in self.servers.values():
if server.id == id:
return server
+ return None
def connect(self, server: IRCServer.Server) -> bool:
try:
diff --git a/src/IRCBuffer.py b/src/IRCBuffer.py
index 426e15e9..4f4b381a 100644
--- a/src/IRCBuffer.py
+++ b/src/IRCBuffer.py
@@ -40,6 +40,7 @@ class Buffer(object):
if line.from_self and not from_self:
continue
return line
+ return None
def find(self, pattern: typing.Union[str, typing.Pattern[str]], **kwargs
) -> typing.Optional[BufferLine]:
from_self = kwargs.get("from_self", True)
@@ -57,5 +58,6 @@ class Buffer(object):
line.sender) == for_user:
continue
return line
+ return None
def skip_next(self):
self._skip_next = True
diff --git a/src/IRCServer.py b/src/IRCServer.py
index ba04fd2a..2a7ceb3b 100644
--- a/src/IRCServer.py
+++ b/src/IRCServer.py
@@ -26,36 +26,36 @@ class Server(IRCObject.Object):
self.original_nickname = nickname
self.original_username = username or nickname
self.original_realname = realname or nickname
- self.name = None
+ self.name = None # type: typing.Optional[str]
- self._capability_queue = set([])
- self._capabilities_waiting = set([])
- self.capabilities = set([])
- self.server_capabilities = {}
- self.batches = {}
+ self._capability_queue = set([]) # type: typing.Set[str]
+ self._capabilities_waiting = set([]) # type: typing.Set[str]
+ self.capabilities = set([]) # type: typing.Set[str]
+ self.server_capabilities = {} # type: typing.Dict[str, str]
+ self.batches = {} # type: typing.Dict[str, utils.irc.IRCLine]
self.write_buffer = b""
- self.buffered_lines = []
+ self.buffered_lines = [] # type: typing.List[bytes]
self.read_buffer = b""
- self.recent_sends = []
+ self.recent_sends = [] # type: typing.List[float]
- self.users = {}
- self.new_users = set([])
- self.channels = {}
+ self.users = {} # type: typing.Dict[str, IRCUser.User]
+ self.new_users = set([]) #type: typing.Set[IRCUser.User]
+ self.channels = {} # type: typing.Dict[str, IRCChannel.Channel]
- self.own_modes = {}
+ self.own_modes = {} # type: typing.Dict[str, typing.Optional[str]]
self.prefix_symbols = collections.OrderedDict(
(("@", "o"), ("+", "v")))
self.prefix_modes = collections.OrderedDict(
(("o", "@"), ("v", "+")))
- self.channel_modes = []
+ self.channel_modes = [] # type: typing.List[str]
self.channel_types = ["#"]
self.case_mapping = "rfc1459"
self.last_read = time.monotonic()
- self.last_send = None
+ self.last_send = None # type: typing.Optional[float]
- self.attempted_join = {}
+ self.attempted_join = {} # type: typing.Dict[str, typing.Optional[str]]
self.ping_sent = False
if ipv4:
diff --git a/src/IRCUser.py b/src/IRCUser.py
index 7d7721b4..03543d5f 100644
--- a/src/IRCUser.py
+++ b/src/IRCUser.py
@@ -11,7 +11,7 @@ class User(IRCObject.Object):
self.hostname = None
self.realname = None
self.bot = bot
- self.channels = set([])
+ self.channels = set([]) # type: typing.Set[IRCChannel.Channel]
self.identified_account = None
self.identified_account_override = None
diff --git a/src/utils/__init__.py b/src/utils/__init__.py
index f60c199e..d29197df 100644
--- a/src/utils/__init__.py
+++ b/src/utils/__init__.py
@@ -52,6 +52,7 @@ def from_pretty_time(pretty_time: str) -> typing.Optional[int]:
seconds += number
if seconds > 0:
return seconds
+ return None
UNIT_MINIMUM = 6
UNIT_SECOND = 5
@@ -117,10 +118,12 @@ def bool_or_none(s: str) -> typing.Optional[bool]:
return True
elif s in IS_FALSE:
return False
+ return None
def int_or_none(s: str) -> typing.Optional[int]:
stripped_s = s.lstrip("0")
if stripped_s.isdigit():
return int(stripped_s)
+ return None
def prevent_highlight(nickname: str) -> str:
return nickname[0]+"\u200c"+nickname[1:]