mirror of
https://github.com/jlu5/PyLink.git
synced 2024-11-01 01:09:22 +01:00
use isinstance() instead of type() where appropriate #410
This commit is contained in:
parent
87fe7693b0
commit
7ab0e8f105
13
classes.py
13
classes.py
@ -507,7 +507,7 @@ class PyLinkNetworkCoreWithUtils(PyLinkNetworkCore):
|
||||
# C = Mode that changes a setting and only has a parameter when set.
|
||||
# D = Mode that changes a setting and never has a parameter.
|
||||
|
||||
if type(args) == str:
|
||||
if isinstance(args, str):
|
||||
# If the modestring was given as a string, split it into a list.
|
||||
args = args.split()
|
||||
|
||||
@ -697,9 +697,10 @@ class PyLinkNetworkCoreWithUtils(PyLinkNetworkCore):
|
||||
=> {('-m', None), ('-r', None), ('-l', None), ('+o', 'person')})
|
||||
{('s', None), ('+o', 'whoever') => {('-s', None), ('-o', 'whoever')})
|
||||
"""
|
||||
origtype = type(modes)
|
||||
origstring = isinstance(modes, str)
|
||||
|
||||
# If the query is a string, we have to parse it first.
|
||||
if origtype == str:
|
||||
if origstring:
|
||||
modes = self.parse_modes(target, modes.split(" "))
|
||||
# Get the current mode list first.
|
||||
if utils.isChannel(target):
|
||||
@ -755,7 +756,7 @@ class PyLinkNetworkCoreWithUtils(PyLinkNetworkCore):
|
||||
newmodes.append(mpair)
|
||||
|
||||
log.debug('(%s) reverse_modes: new modes: %s', self.name, newmodes)
|
||||
if origtype == str:
|
||||
if origstring:
|
||||
# If the original query is a string, send it back as a string.
|
||||
return self.join_modes(newmodes)
|
||||
else:
|
||||
@ -1074,8 +1075,8 @@ class PyLinkNetworkCoreWithUtils(PyLinkNetworkCore):
|
||||
# conditions that would otherwise desync channel modes.
|
||||
with self._ts_lock:
|
||||
our_ts = self.channels[channel].ts
|
||||
assert type(our_ts) == int, "Wrong type for our_ts (expected int, got %s)" % type(our_ts)
|
||||
assert type(their_ts) == int, "Wrong type for their_ts (expected int, got %s)" % type(their_ts)
|
||||
assert isinstance(our_ts, int), "Wrong type for our_ts (expected int, got %s)" % type(our_ts)
|
||||
assert isinstance(their_ts, int), "Wrong type for their_ts (expected int, got %s)" % type(their_ts)
|
||||
|
||||
# Check if we're the mode sender based on the UID / SID given.
|
||||
our_mode = self.is_internal_client(sender) or self.is_internal_server(sender)
|
||||
|
@ -151,7 +151,7 @@ class IRCCommonProtocol(IRCNetwork):
|
||||
Parses a string of capabilities in the 005 / RPL_ISUPPORT format.
|
||||
"""
|
||||
|
||||
if type(args) == str:
|
||||
if isinstance(args, str):
|
||||
args = args.split(' ')
|
||||
|
||||
caps = {}
|
||||
|
4
utils.py
4
utils.py
@ -243,13 +243,13 @@ class ServiceBot():
|
||||
Joins the given service bot to the given channel(s).
|
||||
"""
|
||||
|
||||
if type(irc) == str:
|
||||
if isinstance(irc, str):
|
||||
netname = irc
|
||||
else:
|
||||
netname = irc.name
|
||||
|
||||
# Ensure type safety: pluralize strings if only one channel was given, then convert to set.
|
||||
if type(channels) == str:
|
||||
if isinstance(channels, str):
|
||||
channels = [channels]
|
||||
channels = set(channels)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user