forked from LBRYCommunity/lbry-sdk
pylint type checking
This commit is contained in:
parent
d6e7fde90a
commit
cdf67de46c
6 changed files with 19 additions and 20 deletions
|
@ -112,7 +112,6 @@ disable=
|
||||||
trailing-newlines,
|
trailing-newlines,
|
||||||
undefined-loop-variable,
|
undefined-loop-variable,
|
||||||
ungrouped-imports,
|
ungrouped-imports,
|
||||||
unidiomatic-typecheck,
|
|
||||||
unnecessary-lambda,
|
unnecessary-lambda,
|
||||||
unused-argument,
|
unused-argument,
|
||||||
unused-variable,
|
unused-variable,
|
||||||
|
|
|
@ -51,7 +51,7 @@ class ClaimOutpoint(dict):
|
||||||
return (self['txid'], self['nout']) == (compare['txid'], compare['nOut'])
|
return (self['txid'], self['nout']) == (compare['txid'], compare['nOut'])
|
||||||
elif 'nout' in compare:
|
elif 'nout' in compare:
|
||||||
return (self['txid'], self['nout']) == (compare['txid'], compare['nout'])
|
return (self['txid'], self['nout']) == (compare['txid'], compare['nout'])
|
||||||
elif type(compare) in [str, unicode]:
|
elif isinstance(compare, (str, unicode)):
|
||||||
return compare == self.__repr__()
|
return compare == self.__repr__()
|
||||||
else:
|
else:
|
||||||
raise TypeError('cannot compare {}'.format(type(compare)))
|
raise TypeError('cannot compare {}'.format(type(compare)))
|
||||||
|
|
|
@ -241,7 +241,7 @@ class RequestHelper(object):
|
||||||
def _handle_incoming_blob(response_dict, peer, request):
|
def _handle_incoming_blob(response_dict, peer, request):
|
||||||
if request.response_identifier not in response_dict:
|
if request.response_identifier not in response_dict:
|
||||||
return InvalidResponseError("response identifier not in response")
|
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" %
|
return InvalidResponseError("response not a dict. got %s" %
|
||||||
type(response_dict[request.response_identifier]))
|
type(response_dict[request.response_identifier]))
|
||||||
response = response_dict[request.response_identifier]
|
response = response_dict[request.response_identifier]
|
||||||
|
|
|
@ -63,16 +63,16 @@ class Bencode(Encoding):
|
||||||
@return: The encoded data
|
@return: The encoded data
|
||||||
@rtype: str
|
@rtype: str
|
||||||
"""
|
"""
|
||||||
if type(data) in (int, long):
|
if isinstance(data, (int, long)):
|
||||||
return 'i%de' % data
|
return 'i%de' % data
|
||||||
elif type(data) == str:
|
elif isinstance(data, str):
|
||||||
return '%d:%s' % (len(data), data)
|
return '%d:%s' % (len(data), data)
|
||||||
elif type(data) in (list, tuple):
|
elif isinstance(data, (list, tuple)):
|
||||||
encodedListItems = ''
|
encodedListItems = ''
|
||||||
for item in data:
|
for item in data:
|
||||||
encodedListItems += self.encode(item)
|
encodedListItems += self.encode(item)
|
||||||
return 'l%se' % encodedListItems
|
return 'l%se' % encodedListItems
|
||||||
elif type(data) == dict:
|
elif isinstance(data, dict):
|
||||||
encodedDictItems = ''
|
encodedDictItems = ''
|
||||||
keys = data.keys()
|
keys = data.keys()
|
||||||
keys.sort()
|
keys.sort()
|
||||||
|
@ -80,7 +80,7 @@ class Bencode(Encoding):
|
||||||
encodedDictItems += self.encode(key)
|
encodedDictItems += self.encode(key)
|
||||||
encodedDictItems += self.encode(data[key])
|
encodedDictItems += self.encode(data[key])
|
||||||
return 'd%se' % encodedDictItems
|
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
|
# This (float data type) is a non-standard extension to the original Bencode algorithm
|
||||||
return 'f%fe' % data
|
return 'f%fe' % data
|
||||||
elif data is None:
|
elif data is None:
|
||||||
|
@ -89,7 +89,7 @@ class Bencode(Encoding):
|
||||||
return 'n'
|
return 'n'
|
||||||
else:
|
else:
|
||||||
print data
|
print data
|
||||||
raise TypeError, "Cannot bencode '%s' object" % type(data)
|
raise TypeError("Cannot bencode '%s' object" % type(data))
|
||||||
|
|
||||||
def decode(self, data):
|
def decode(self, data):
|
||||||
""" Decoder implementation of the Bencode algorithm
|
""" Decoder implementation of the Bencode algorithm
|
||||||
|
@ -104,11 +104,11 @@ class Bencode(Encoding):
|
||||||
@rtype: int, list, dict or str
|
@rtype: int, list, dict or str
|
||||||
"""
|
"""
|
||||||
if len(data) == 0:
|
if len(data) == 0:
|
||||||
raise DecodeError, 'Cannot decode empty string'
|
raise DecodeError('Cannot decode empty string')
|
||||||
try:
|
try:
|
||||||
return self._decodeRecursive(data)[0]
|
return self._decodeRecursive(data)[0]
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
raise DecodeError, e.message
|
raise DecodeError(e.message)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _decodeRecursive(data, startIndex=0):
|
def _decodeRecursive(data, startIndex=0):
|
||||||
|
@ -118,14 +118,14 @@ class Bencode(Encoding):
|
||||||
"""
|
"""
|
||||||
if data[startIndex] == 'i':
|
if data[startIndex] == 'i':
|
||||||
endPos = data[startIndex:].find('e') + startIndex
|
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':
|
elif data[startIndex] == 'l':
|
||||||
startIndex += 1
|
startIndex += 1
|
||||||
decodedList = []
|
decodedList = []
|
||||||
while data[startIndex] != 'e':
|
while data[startIndex] != 'e':
|
||||||
listData, startIndex = Bencode._decodeRecursive(data, startIndex)
|
listData, startIndex = Bencode._decodeRecursive(data, startIndex)
|
||||||
decodedList.append(listData)
|
decodedList.append(listData)
|
||||||
return (decodedList, startIndex + 1)
|
return decodedList, startIndex + 1
|
||||||
elif data[startIndex] == 'd':
|
elif data[startIndex] == 'd':
|
||||||
startIndex += 1
|
startIndex += 1
|
||||||
decodedDict = {}
|
decodedDict = {}
|
||||||
|
@ -133,15 +133,15 @@ class Bencode(Encoding):
|
||||||
key, startIndex = Bencode._decodeRecursive(data, startIndex)
|
key, startIndex = Bencode._decodeRecursive(data, startIndex)
|
||||||
value, startIndex = Bencode._decodeRecursive(data, startIndex)
|
value, startIndex = Bencode._decodeRecursive(data, startIndex)
|
||||||
decodedDict[key] = value
|
decodedDict[key] = value
|
||||||
return (decodedDict, startIndex)
|
return decodedDict, startIndex
|
||||||
elif data[startIndex] == 'f':
|
elif data[startIndex] == 'f':
|
||||||
# This (float data type) is a non-standard extension to the original Bencode algorithm
|
# This (float data type) is a non-standard extension to the original Bencode algorithm
|
||||||
endPos = data[startIndex:].find('e') + startIndex
|
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':
|
elif data[startIndex] == 'n':
|
||||||
# This (None/NULL data type) is a non-standard extension
|
# This (None/NULL data type) is a non-standard extension
|
||||||
# to the original Bencode algorithm
|
# to the original Bencode algorithm
|
||||||
return (None, startIndex + 1)
|
return None, startIndex + 1
|
||||||
else:
|
else:
|
||||||
splitPos = data[startIndex:].find(':') + startIndex
|
splitPos = data[startIndex:].find(':') + startIndex
|
||||||
try:
|
try:
|
||||||
|
@ -151,4 +151,4 @@ class Bencode(Encoding):
|
||||||
startIndex = splitPos + 1
|
startIndex = splitPos + 1
|
||||||
endPos = startIndex + length
|
endPos = startIndex + length
|
||||||
bytes = data[startIndex:endPos]
|
bytes = data[startIndex:endPos]
|
||||||
return (bytes, endPos)
|
return bytes, endPos
|
||||||
|
|
|
@ -207,7 +207,7 @@ class Node(object):
|
||||||
|
|
||||||
def expand_and_filter(result):
|
def expand_and_filter(result):
|
||||||
expanded_peers = []
|
expanded_peers = []
|
||||||
if type(result) == dict:
|
if isinstance(result, dict):
|
||||||
if blob_hash in result:
|
if blob_hash in result:
|
||||||
for peer in result[blob_hash]:
|
for peer in result[blob_hash]:
|
||||||
if self.lbryid != peer[6:]:
|
if self.lbryid != peer[6:]:
|
||||||
|
@ -353,7 +353,7 @@ class Node(object):
|
||||||
outerDf = defer.Deferred()
|
outerDf = defer.Deferred()
|
||||||
|
|
||||||
def checkResult(result):
|
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...
|
# We have found the value; now see who was the closest contact without it...
|
||||||
# ...and store the key/value pair
|
# ...and store the key/value pair
|
||||||
outerDf.callback(result)
|
outerDf.callback(result)
|
||||||
|
|
|
@ -24,7 +24,7 @@ __version__ = '0.3.0'
|
||||||
def undecorated(o):
|
def undecorated(o):
|
||||||
"""Remove all decorators from a function, method or class"""
|
"""Remove all decorators from a function, method or class"""
|
||||||
# class decorator
|
# class decorator
|
||||||
if type(o) is type:
|
if isinstance(o, type):
|
||||||
return o
|
return o
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in a new issue