From 7ab0e8f1056234ffd26c3a8c8235f6aa59b957e2 Mon Sep 17 00:00:00 2001 From: Mitchell Cooper Date: Wed, 12 Jul 2017 17:29:34 -0400 Subject: [PATCH] use isinstance() instead of type() where appropriate #410 --- classes.py | 13 +++++++------ protocols/ircs2s_common.py | 2 +- utils.py | 4 ++-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/classes.py b/classes.py index b61c39f..fa3d300 100644 --- a/classes.py +++ b/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) diff --git a/protocols/ircs2s_common.py b/protocols/ircs2s_common.py index 77ef471..edcb8f0 100644 --- a/protocols/ircs2s_common.py +++ b/protocols/ircs2s_common.py @@ -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 = {} diff --git a/utils.py b/utils.py index 2f64d8f..396291e 100644 --- a/utils.py +++ b/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)