replaced type() with isinstance() where possible
This commit is contained in:
parent
47bcd4478c
commit
3319feeb73
|
@ -109,7 +109,7 @@ def close(handle):
|
||||||
"""Closes a HID device handle."""
|
"""Closes a HID device handle."""
|
||||||
if handle:
|
if handle:
|
||||||
try:
|
try:
|
||||||
if type(handle) == int:
|
if isinstance(handle, int):
|
||||||
_hid.close(handle)
|
_hid.close(handle)
|
||||||
else:
|
else:
|
||||||
handle.close()
|
handle.close()
|
||||||
|
|
|
@ -120,7 +120,7 @@ class NamedInts(object):
|
||||||
if isinstance(index, int):
|
if isinstance(index, int):
|
||||||
if index in self._indexed:
|
if index in self._indexed:
|
||||||
return self._indexed[int(index)]
|
return self._indexed[int(index)]
|
||||||
if self._fallback and type(index) == int:
|
if self._fallback and isinstance(index, int):
|
||||||
value = NamedInt(index, self._fallback(index))
|
value = NamedInt(index, self._fallback(index))
|
||||||
self._indexed[index] = value
|
self._indexed[index] = value
|
||||||
self._values = sorted(self._values + [value])
|
self._values = sorted(self._values + [value])
|
||||||
|
|
|
@ -35,7 +35,7 @@ class _ThreadedHandle(object):
|
||||||
assert listener is not None
|
assert listener is not None
|
||||||
assert path is not None
|
assert path is not None
|
||||||
assert handle is not None
|
assert handle is not None
|
||||||
assert type(handle) == int
|
assert isinstance(handle, int)
|
||||||
|
|
||||||
self._listener = listener
|
self._listener = listener
|
||||||
self.path = path
|
self.path = path
|
||||||
|
|
|
@ -321,7 +321,7 @@ class Receiver(object):
|
||||||
self.name = 'Nano Receiver'
|
self.name = 'Nano Receiver'
|
||||||
else:
|
else:
|
||||||
raise Exception("unknown receiver type", self.max_devices)
|
raise Exception("unknown receiver type", self.max_devices)
|
||||||
self._str = '<%s(%s,%s%s)>' % (self.name.replace(' ', ''), self.path, '' if type(self.handle) == int else 'T', self.handle)
|
self._str = '<%s(%s,%s%s)>' % (self.name.replace(' ', ''), self.path, '' if isinstance(self.handle, int) else 'T', self.handle)
|
||||||
|
|
||||||
# TODO _properly_ figure out which receivers do and which don't support unpairing
|
# TODO _properly_ figure out which receivers do and which don't support unpairing
|
||||||
self.may_unpair = self.write_register(_R.receiver_pairing) is None
|
self.may_unpair = self.write_register(_R.receiver_pairing) is None
|
||||||
|
@ -429,7 +429,7 @@ class Receiver(object):
|
||||||
if dev is not None:
|
if dev is not None:
|
||||||
return dev
|
return dev
|
||||||
|
|
||||||
if type(key) != int:
|
if not isinstance(key, int):
|
||||||
raise TypeError('key must be an integer')
|
raise TypeError('key must be an integer')
|
||||||
if key < 1 or key > self.max_devices:
|
if key < 1 or key > self.max_devices:
|
||||||
raise IndexError(key)
|
raise IndexError(key)
|
||||||
|
@ -457,7 +457,7 @@ class Receiver(object):
|
||||||
return len([d for d in self._devices.values() if d is not None])
|
return len([d for d in self._devices.values() if d is not None])
|
||||||
|
|
||||||
def __contains__(self, dev):
|
def __contains__(self, dev):
|
||||||
if type(dev) == int:
|
if isinstance(dev, int):
|
||||||
return self._devices.get(dev) is not None
|
return self._devices.get(dev) is not None
|
||||||
|
|
||||||
return self.__contains__(dev.number)
|
return self.__contains__(dev.number)
|
||||||
|
|
Loading…
Reference in New Issue