use () instead of [] where possible

This commit is contained in:
Daniel Pavel 2013-07-19 11:48:40 +02:00
parent 15cb97c56e
commit 5d4d0c07ad
9 changed files with 17 additions and 17 deletions

View File

@ -288,7 +288,7 @@ def make_notification(devnumber, data):
return _HIDPP_Notification(devnumber, sub_id, address, data[2:])
from collections import namedtuple
_HIDPP_Notification = namedtuple('_HIDPP_Notification', ['devnumber', 'sub_id', 'address', 'data'])
_HIDPP_Notification = namedtuple('_HIDPP_Notification', ('devnumber', 'sub_id', 'address', 'data'))
_HIDPP_Notification.__str__ = lambda self: 'Notification(%d,%02X,%02X,%s)' % (self.devnumber, self.sub_id, self.address, _strhex(self.data))
_HIDPP_Notification.__unicode__ = _HIDPP_Notification.__str__
del namedtuple

View File

@ -99,7 +99,7 @@ class NamedInts(object):
if the value already exists in the set (int or string), ValueError will be
raised.
"""
__slots__ = ['__dict__', '_values', '_indexed', '_fallback']
__slots__ = ('__dict__', '_values', '_indexed', '_fallback')
def __init__(self, **kwargs):
def _readable_name(n):

View File

@ -32,7 +32,7 @@ _R = _hidpp10.REGISTERS
from collections import namedtuple
_DeviceDescriptor = namedtuple('_DeviceDescriptor',
['name', 'kind', 'wpid', 'codename', 'protocol', 'registers', 'settings'])
('name', 'kind', 'wpid', 'codename', 'protocol', 'registers', 'settings'))
del namedtuple
DEVICES = {}

View File

@ -136,14 +136,14 @@ REGISTERS = _NamedInts(
#
def read_register(device, register_number, *params):
assert device
assert device, 'tried to read register %02X from invalid device %s' % (register_number, device)
# support long registers by adding a 2 in front of the register number
request_id = 0x8100 | (int(register_number) & 0x2FF)
return device.request(request_id, *params)
def write_register(device, register_number, *value):
assert device
assert device, 'tried to write register %02X to invalid device %s' % (register_number, device)
# support long registers by adding a 2 in front of the register number
request_id = 0x8000 | (int(register_number) & 0x2FF)
return device.request(request_id, *value)

View File

@ -418,7 +418,7 @@ def get_mouse_pointer_info(device):
pointer_info = feature_request(device, FEATURE.MOUSE_POINTER)
if pointer_info:
dpi, flags = _unpack('!HB', pointer_info[:3])
acceleration = ['none', 'low', 'med', 'high' ][flags & 0x3]
acceleration = ('none', 'low', 'med', 'high')[flags & 0x3]
suggest_os_ballistics = (flags & 0x04) != 0
suggest_vertical_orientation = (flags & 0x08) != 0
return {

View File

@ -45,7 +45,7 @@ class _ThreadedHandle(object):
Closing a ThreadedHandle will close all handles.
"""
__slots__ = ['path', '_local', '_handles', '_listener']
__slots__ = ('path', '_local', '_handles', '_listener')
def __init__(self, listener, path, handle):
assert listener is not None

View File

@ -41,8 +41,8 @@ KIND = _NamedInts(toggle=0x01, choice=0x02, range=0x12)
class Setting(object):
"""A setting descriptor.
Needs to be instantiated for each specific device."""
__slots__ = ['name', 'label', 'description', 'kind', 'persister', 'device_kind',
'_rw', '_validator', '_device', '_value']
__slots__ = ('name', 'label', 'description', 'kind', 'persister', 'device_kind',
'_rw', '_validator', '_device', '_value')
def __init__(self, name, rw, validator, kind=None, label=None, description=None, device_kind=None):
assert name
@ -163,7 +163,7 @@ class Setting(object):
#
class RegisterRW(object):
__slots__ = ['register']
__slots__ = ('register', )
kind = _NamedInt(0x01, 'register')
@ -179,7 +179,7 @@ class RegisterRW(object):
class FeatureRW(object):
__slots__ = ['feature', 'read_fnid', 'write_fnid']
__slots__ = ('feature', 'read_fnid', 'write_fnid')
kind = _NamedInt(0x02, 'feature')
default_read_fnid = 0x00
@ -205,7 +205,7 @@ class FeatureRW(object):
#
class BooleanValidator(object):
__slots__ = ['true_value', 'false_value', 'mask', 'needs_current_value']
__slots__ = ('true_value', 'false_value', 'mask', 'needs_current_value')
kind = KIND.toggle
default_true = 0x01
@ -313,7 +313,7 @@ class BooleanValidator(object):
class ChoicesValidator(object):
__slots__ = ['choices', 'flag', '_bytes_count', 'needs_current_value']
__slots__ = ('choices', 'flag', '_bytes_count', 'needs_current_value')
kind = KIND.choice

View File

@ -323,9 +323,9 @@ def config_device(receiver, args):
try:
value = bool(int(value))
except:
if value.lower() in ['1', 'true', 'yes', 'on', 't', 'y']:
if value.lower() in ('1', 'true', 'yes', 'on', 't', 'y'):
value = True
elif value.lower() in ['0', 'false', 'no', 'off', 'f', 'n']:
elif value.lower() in ('0', 'false', 'no', 'off', 'f', 'n'):
value = False
else:
_fail("don't know how to interpret '%s' as boolean" % value)
@ -333,7 +333,7 @@ def config_device(receiver, args):
elif setting.choices:
value = args.value.lower()
if value in ['higher', 'lower']:
if value in ('higher', 'lower'):
old_value = setting.read()
if old_value is None:
_fail("could not read current value of '%s'" % setting.name)

View File

@ -38,7 +38,7 @@ from logitech_receiver import (
#
from collections import namedtuple
_GHOST_DEVICE = namedtuple('_GHOST_DEVICE', ['receiver', 'number', 'name', 'kind', 'status', 'online'])
_GHOST_DEVICE = namedtuple('_GHOST_DEVICE', ('receiver', 'number', 'name', 'kind', 'status', 'online'))
_GHOST_DEVICE.__bool__ = lambda self: False
_GHOST_DEVICE.__nonzero__ = _GHOST_DEVICE.__bool__
del namedtuple