Fix some non-explicit None returns, add type hints to important variables

This commit is contained in:
jesopo 2018-10-31 15:12:46 +00:00
parent 7d54bd6ad0
commit a4d8d1f855
6 changed files with 23 additions and 17 deletions

View file

@ -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):

View file

@ -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:

View file

@ -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

View file

@ -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:

View file

@ -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

View file

@ -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:]