diff --git a/.pylintrc b/.pylintrc index f1be5b61b..3d95c0cfe 100644 --- a/.pylintrc +++ b/.pylintrc @@ -112,7 +112,6 @@ disable= trailing-newlines, undefined-loop-variable, ungrouped-imports, - unidiomatic-typecheck, unnecessary-lambda, unused-argument, unused-variable, diff --git a/lbrynet/core/Wallet.py b/lbrynet/core/Wallet.py index dd5c8507e..791fac047 100644 --- a/lbrynet/core/Wallet.py +++ b/lbrynet/core/Wallet.py @@ -51,7 +51,7 @@ class ClaimOutpoint(dict): return (self['txid'], self['nout']) == (compare['txid'], compare['nOut']) elif 'nout' in compare: return (self['txid'], self['nout']) == (compare['txid'], compare['nout']) - elif type(compare) in [str, unicode]: + elif isinstance(compare, (str, unicode)): return compare == self.__repr__() else: raise TypeError('cannot compare {}'.format(type(compare))) diff --git a/lbrynet/core/client/BlobRequester.py b/lbrynet/core/client/BlobRequester.py index d1681b0db..ee9fa5e1b 100644 --- a/lbrynet/core/client/BlobRequester.py +++ b/lbrynet/core/client/BlobRequester.py @@ -241,7 +241,7 @@ class RequestHelper(object): def _handle_incoming_blob(response_dict, peer, request): if request.response_identifier not in response_dict: return InvalidResponseError("response identifier not in response") - if type(response_dict[request.response_identifier]) != dict: + if not isinstance(response_dict[request.response_identifier], dict): return InvalidResponseError("response not a dict. got %s" % type(response_dict[request.response_identifier])) response = response_dict[request.response_identifier] diff --git a/lbrynet/dht/encoding.py b/lbrynet/dht/encoding.py index 08081d95a..bc7e88ca0 100644 --- a/lbrynet/dht/encoding.py +++ b/lbrynet/dht/encoding.py @@ -63,16 +63,16 @@ class Bencode(Encoding): @return: The encoded data @rtype: str """ - if type(data) in (int, long): + if isinstance(data, (int, long)): return 'i%de' % data - elif type(data) == str: + elif isinstance(data, str): return '%d:%s' % (len(data), data) - elif type(data) in (list, tuple): + elif isinstance(data, (list, tuple)): encodedListItems = '' for item in data: encodedListItems += self.encode(item) return 'l%se' % encodedListItems - elif type(data) == dict: + elif isinstance(data, dict): encodedDictItems = '' keys = data.keys() keys.sort() @@ -80,7 +80,7 @@ class Bencode(Encoding): encodedDictItems += self.encode(key) encodedDictItems += self.encode(data[key]) return 'd%se' % encodedDictItems - elif type(data) == float: + elif isinstance(data, float): # This (float data type) is a non-standard extension to the original Bencode algorithm return 'f%fe' % data elif data is None: @@ -89,7 +89,7 @@ class Bencode(Encoding): return 'n' else: print data - raise TypeError, "Cannot bencode '%s' object" % type(data) + raise TypeError("Cannot bencode '%s' object" % type(data)) def decode(self, data): """ Decoder implementation of the Bencode algorithm @@ -104,11 +104,11 @@ class Bencode(Encoding): @rtype: int, list, dict or str """ if len(data) == 0: - raise DecodeError, 'Cannot decode empty string' + raise DecodeError('Cannot decode empty string') try: return self._decodeRecursive(data)[0] except ValueError as e: - raise DecodeError, e.message + raise DecodeError(e.message) @staticmethod def _decodeRecursive(data, startIndex=0): @@ -118,14 +118,14 @@ class Bencode(Encoding): """ if data[startIndex] == 'i': endPos = data[startIndex:].find('e') + startIndex - return (int(data[startIndex + 1:endPos]), endPos + 1) + return int(data[startIndex + 1:endPos]), endPos + 1 elif data[startIndex] == 'l': startIndex += 1 decodedList = [] while data[startIndex] != 'e': listData, startIndex = Bencode._decodeRecursive(data, startIndex) decodedList.append(listData) - return (decodedList, startIndex + 1) + return decodedList, startIndex + 1 elif data[startIndex] == 'd': startIndex += 1 decodedDict = {} @@ -133,15 +133,15 @@ class Bencode(Encoding): key, startIndex = Bencode._decodeRecursive(data, startIndex) value, startIndex = Bencode._decodeRecursive(data, startIndex) decodedDict[key] = value - return (decodedDict, startIndex) + return decodedDict, startIndex elif data[startIndex] == 'f': # This (float data type) is a non-standard extension to the original Bencode algorithm endPos = data[startIndex:].find('e') + startIndex - return (float(data[startIndex + 1:endPos]), endPos + 1) + return float(data[startIndex + 1:endPos]), endPos + 1 elif data[startIndex] == 'n': # This (None/NULL data type) is a non-standard extension # to the original Bencode algorithm - return (None, startIndex + 1) + return None, startIndex + 1 else: splitPos = data[startIndex:].find(':') + startIndex try: @@ -151,4 +151,4 @@ class Bencode(Encoding): startIndex = splitPos + 1 endPos = startIndex + length bytes = data[startIndex:endPos] - return (bytes, endPos) + return bytes, endPos diff --git a/lbrynet/dht/node.py b/lbrynet/dht/node.py index 3c66936b7..25e209db4 100644 --- a/lbrynet/dht/node.py +++ b/lbrynet/dht/node.py @@ -207,7 +207,7 @@ class Node(object): def expand_and_filter(result): expanded_peers = [] - if type(result) == dict: + if isinstance(result, dict): if blob_hash in result: for peer in result[blob_hash]: if self.lbryid != peer[6:]: @@ -353,7 +353,7 @@ class Node(object): outerDf = defer.Deferred() def checkResult(result): - if type(result) == dict: + if isinstance(result, dict): # We have found the value; now see who was the closest contact without it... # ...and store the key/value pair outerDf.callback(result) diff --git a/lbrynet/undecorated.py b/lbrynet/undecorated.py index 3a95cad5d..3395be714 100644 --- a/lbrynet/undecorated.py +++ b/lbrynet/undecorated.py @@ -24,7 +24,7 @@ __version__ = '0.3.0' def undecorated(o): """Remove all decorators from a function, method or class""" # class decorator - if type(o) is type: + if isinstance(o, type): return o try: