Prefer dict literal syntax over dict() (#787)

* Prefer dict literal syntax over dict()

* An overlooked dict-constructor in transport/SQS.py
This commit is contained in:
Mads Jensen 2017-09-08 06:43:59 +02:00 committed by Omer Katz
parent c292e9d400
commit 65d203c71e
9 changed files with 53 additions and 52 deletions

View File

@ -83,6 +83,7 @@ Latitia M. Haskins <lhaskins@jetsonsys.com>
Len Buckens <buckens.len@gmail.com> Len Buckens <buckens.len@gmail.com>
Lorenzo Mancini <lmancini@develer.com> Lorenzo Mancini <lmancini@develer.com>
Luyun Xie <2304310@qq.com> Luyun Xie <2304310@qq.com>
Mads Jensen <https://github.com/atombrella>
Mahendra M <Mahendra_M@infosys.com> Mahendra M <Mahendra_M@infosys.com>
Marcin Lulek (ergo) <info@webreactor.eu> Marcin Lulek (ergo) <info@webreactor.eu>
Mark Lavin <mlavin@caktusgroup.com> Mark Lavin <mlavin@caktusgroup.com>

View File

@ -144,8 +144,8 @@ class SimpleBuffer(SimpleQueue):
"""Simple API for ephemeral queues.""" """Simple API for ephemeral queues."""
no_ack = True no_ack = True
queue_opts = dict(durable=False, queue_opts = {'durable': False,
auto_delete=True) 'auto_delete': True}
exchange_opts = dict(durable=False, exchange_opts = {'durable': False,
delivery_mode='transient', 'delivery_mode': 'transient',
auto_delete=True) 'auto_delete': True}

View File

@ -420,9 +420,9 @@ class Channel(virtual.Channel):
aws_secret_access_key=self.conninfo.password, aws_secret_access_key=self.conninfo.password,
) )
is_secure = self.is_secure if self.is_secure is not None else True is_secure = self.is_secure if self.is_secure is not None else True
client_kwargs = dict( client_kwargs = {
use_ssl=is_secure 'use_ssl': is_secure
) }
if self.endpoint_url is not None: if self.endpoint_url is not None:
client_kwargs['endpoint_url'] = self.endpoint_url client_kwargs['endpoint_url'] = self.endpoint_url
self._sqs = session.client('sqs', **client_kwargs) self._sqs = session.client('sqs', **client_kwargs)

View File

@ -381,15 +381,15 @@ class Channel(virtual.Channel):
def _create_broadcast_cursor(self, exchange, routing_key, pattern, queue): def _create_broadcast_cursor(self, exchange, routing_key, pattern, queue):
if pymongo.version_tuple >= (3, ): if pymongo.version_tuple >= (3, ):
query = dict( query = {
filter={'queue': exchange}, 'filter': {'queue': exchange},
cursor_type=CursorType.TAILABLE 'cursor_type': CursorType.TAILABLE,
) }
else: else:
query = dict( query = {
query={'queue': exchange}, 'query': {'queue': exchange},
tailable=True 'tailable': True,
) }
cursor = self.broadcast.find(**query) cursor = self.broadcast.find(**query)
ret = self._broadcast_cursors[queue] = BroadcastCursor(cursor) ret = self._broadcast_cursors[queue] = BroadcastCursor(cursor)

View File

@ -857,7 +857,7 @@ class Management(base.Management):
self.channel = transport.client.channel() self.channel = transport.client.channel()
def get_bindings(self): def get_bindings(self):
return [dict(destination=q, source=e, routing_key=r) return [{'destination': q, 'source': e, 'routing_key': r}
for q, e, r in self.channel.list_bindings()] for q, e, r in self.channel.list_bindings()]
def close(self): def close(self):

View File

@ -67,12 +67,12 @@ class Channel(base.StdChannel):
def prepare_message(self, body, priority=0, content_type=None, def prepare_message(self, body, priority=0, content_type=None,
content_encoding=None, headers=None, properties={}): content_encoding=None, headers=None, properties={}):
self._called('prepare_message') self._called('prepare_message')
return dict(body=body, return {'body': body,
headers=headers, 'headers': headers,
properties=properties, 'properties': properties,
priority=priority, 'priority': priority,
content_type=content_type, 'content_type': content_type,
content_encoding=content_encoding) 'content_encoding': content_encoding}
def basic_publish(self, message, exchange='', routing_key='', def basic_publish(self, message, exchange='', routing_key='',
mandatory=False, immediate=False, **kwargs): mandatory=False, immediate=False, **kwargs):

View File

@ -65,38 +65,38 @@ class test_connection_utils:
@pytest.mark.parametrize('url,expected', [ @pytest.mark.parametrize('url,expected', [
('amqp://user:pass@host:10000/vhost', ('amqp://user:pass@host:10000/vhost',
dict(userid='user', password='pass', hostname='host', {'userid': 'user', 'password': 'pass', 'hostname': 'host',
port=10000, virtual_host='vhost')), 'port': 10000, 'virtual_host': 'vhost'}),
('amqp://user%61:%61pass@ho%61st:10000/v%2fhost', ('amqp://user%61:%61pass@ho%61st:10000/v%2fhost',
dict(userid='usera', password='apass', hostname='hoast', {'userid': 'usera', 'password': 'apass', 'hostname': 'hoast',
port=10000, virtual_host='v/host')), 'port': 10000, 'virtual_host': 'v/host'}),
('amqp://', ('amqp://',
dict(userid='guest', password='guest', hostname='localhost', {'userid': 'guest', 'password': 'guest', 'hostname': 'localhost',
port=5672, virtual_host='/')), 'port': 5672, 'virtual_host': '/'}),
('amqp://:@/', ('amqp://:@/',
dict(userid='guest', password='guest', hostname='localhost', {'userid': 'guest', 'password': 'guest', 'hostname': 'localhost',
port=5672, virtual_host='/')), 'port': 5672, 'virtual_host': '/'}),
('amqp://user@/', ('amqp://user@/',
dict(userid='user', password='guest', hostname='localhost', {'userid': 'user', 'password': 'guest', 'hostname': 'localhost',
port=5672, virtual_host='/')), 'port': 5672, 'virtual_host': '/'}),
('amqp://user:pass@/', ('amqp://user:pass@/',
dict(userid='user', password='pass', hostname='localhost', {'userid': 'user', 'password': 'pass', 'hostname': 'localhost',
port=5672, virtual_host='/')), 'port': 5672, 'virtual_host': '/'}),
('amqp://host', ('amqp://host',
dict(userid='guest', password='guest', hostname='host', {'userid': 'guest', 'password': 'guest', 'hostname': 'host',
port=5672, virtual_host='/')), 'port': 5672, 'virtual_host': '/'}),
('amqp://:10000', ('amqp://:10000',
dict(userid='guest', password='guest', hostname='localhost', {'userid': 'guest', 'password': 'guest', 'hostname': 'localhost',
port=10000, virtual_host='/')), 'port': 10000, 'virtual_host': '/'}),
('amqp:///vhost', ('amqp:///vhost',
dict(userid='guest', password='guest', hostname='localhost', {'userid': 'guest', 'password': 'guest', 'hostname': 'localhost',
port=5672, virtual_host='vhost')), 'port': 5672, 'virtual_host': 'vhost'}),
('amqp://host/', ('amqp://host/',
dict(userid='guest', password='guest', hostname='host', {'userid': 'guest', 'password': 'guest', 'hostname': 'host',
port=5672, virtual_host='/')), 'port': 5672, 'virtual_host': '/'}),
('amqp://host/%2f', ('amqp://host/%2f',
dict(userid='guest', password='guest', hostname='host', {'userid': 'guest', 'password': 'guest', 'hostname': 'host',
port=5672, virtual_host='/')), 'port': 5672, 'virtual_host': '/'}),
]) ])
def test_rabbitmq_example_urls(self, url, expected): def test_rabbitmq_example_urls(self, url, expected):
# see Appendix A of http://www.rabbitmq.com/uri-spec.html # see Appendix A of http://www.rabbitmq.com/uri-spec.html

View File

@ -553,7 +553,7 @@ class test_Transport:
self.transport = client().transport self.transport = client().transport
def test_custom_polling_interval(self): def test_custom_polling_interval(self):
x = client(transport_options=dict(polling_interval=32.3)) x = client(transport_options={'polling_interval': 32.3})
assert x.transport.polling_interval == 32.3 assert x.transport.polling_interval == 32.3
def test_close_connection(self): def test_close_connection(self):

View File

@ -145,12 +145,12 @@ class test_ExchangeType(ExchangeCase):
'rFoo', None, 'qFoo', 'rFoo', None, 'qFoo',
) )
e1 = dict( e1 = {
type='direct', 'type': 'direct',
durable=True, 'durable': True,
auto_delete=True, 'auto_delete': True,
arguments={}, 'arguments': {},
) }
e2 = dict(e1, arguments={'expires': 3000}) e2 = dict(e1, arguments={'expires': 3000})
@pytest.mark.parametrize('ex,eq,name,type,durable,auto_delete,arguments', [ @pytest.mark.parametrize('ex,eq,name,type,durable,auto_delete,arguments', [