launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #06548
[Merge] lp:~allenap/maas/python-3-lint-redux into lp:maas
Gavin Panella has proposed merging lp:~allenap/maas/python-3-lint-redux into lp:maas.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~allenap/maas/python-3-lint-redux/+merge/95161
Inspired by jtv's python-3-lint branch, here are some more.
First up it removes u'' strings; we don't need them because we use unicode_literals.
Second it avoids dict.keys(). The behaviour changes between 2.7 and 3.x, so side-stepping it during the transition works. When a list is needed, list(dict) works the same in 2.7 and 3.x, and membership (x in dict) and iteration work the same too.
Thirdly it removes use of filter, which returns an iterator in 3.x. I should have probably also stopped using map too, but haven't yet.
Fourthly and lastly, it avoids unwrapping in argument lists, something 2to3 picked up. See amq_connected for an example.
--
https://code.launchpad.net/~allenap/maas/python-3-lint-redux/+merge/95161
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~allenap/maas/python-3-lint-redux into lp:maas.
=== modified file 'src/maasserver/fields.py'
--- src/maasserver/fields.py 2012-02-21 11:52:58 +0000
+++ src/maasserver/fields.py 2012-02-29 12:27:19 +0000
@@ -33,7 +33,7 @@
mac_re = re.compile(r'^([0-9a-fA-F]{2}[:-]){5}[0-9a-fA-F]{2}$')
-mac_error_msg = u"Enter a valid MAC address (e.g. AA:BB:CC:DD:EE:FF)."
+mac_error_msg = "Enter a valid MAC address (e.g. AA:BB:CC:DD:EE:FF)."
validate_mac = RegexValidator(regex=mac_re, message=mac_error_msg)
=== modified file 'src/maasserver/forms.py'
--- src/maasserver/forms.py 2012-02-29 12:00:36 +0000
+++ src/maasserver/forms.py 2012-02-29 12:27:19 +0000
@@ -39,7 +39,8 @@
INVALID_ARCHITECTURE_MESSAGE = (
"%(value)s is not a valid architecture. " +
- "It should be one of: %s." % ", ".join(dict(ARCHITECTURE_CHOICES).keys()))
+ "It should be one of: %s." % ", ".join(
+ name for name, value in ARCHITECTURE_CHOICES))
class NodeForm(ModelForm):
=== modified file 'src/maasserver/models.py'
--- src/maasserver/models.py 2012-02-28 17:40:39 +0000
+++ src/maasserver/models.py 2012-02-29 12:27:19 +0000
@@ -351,7 +351,7 @@
def __unicode__(self):
if self.hostname:
- return u"%s (%s)" % (self.system_id, self.hostname)
+ return "%s (%s)" % (self.system_id, self.hostname)
else:
return self.system_id
=== modified file 'src/maasserver/testing/tests/test_module.py'
--- src/maasserver/testing/tests/test_module.py 2012-02-16 11:51:13 +0000
+++ src/maasserver/testing/tests/test_module.py 2012-02-29 12:27:19 +0000
@@ -32,9 +32,9 @@
[distro_name] = papi_fake.distros
expected_distros = {
distro_name: {
- u'initrd': u'initrd',
- u'kernel': u'kernel',
- u'name': distro_name,
+ 'initrd': 'initrd',
+ 'kernel': 'kernel',
+ 'name': distro_name,
},
}
self.assertEqual(expected_distros, papi_fake.distros)
@@ -43,8 +43,8 @@
[profile_name] = papi_fake.profiles
expected_profiles = {
profile_name: {
- u'distro': distro_name,
- u'name': profile_name,
+ 'distro': distro_name,
+ 'name': profile_name,
},
}
self.assertEqual(expected_profiles, papi_fake.profiles)
=== modified file 'src/maasserver/tests/test_api.py'
--- src/maasserver/tests/test_api.py 2012-02-29 10:31:49 +0000
+++ src/maasserver/tests/test_api.py 2012-02-29 12:27:19 +0000
@@ -96,7 +96,7 @@
parsed_result = json.loads(response.content)
self.assertItemsEqual(
['hostname', 'system_id', 'macaddress_set', 'architecture'],
- parsed_result.keys())
+ list(parsed_result))
def test_POST_fails_without_operation(self):
# If there is no operation ('op=operation_name') specified in the
@@ -641,7 +641,7 @@
self.assertEqual(
['consumer_key', 'token_key', 'token_secret'],
- sorted(parsed_result.keys()))
+ sorted(parsed_result))
self.assertIsInstance(parsed_result['consumer_key'], basestring)
self.assertIsInstance(parsed_result['token_key'], basestring)
self.assertIsInstance(parsed_result['token_secret'], basestring)
=== modified file 'src/maasserver/tests/test_auth.py'
--- src/maasserver/tests/test_auth.py 2012-02-22 14:25:26 +0000
+++ src/maasserver/tests/test_auth.py 2012-02-29 12:27:19 +0000
@@ -48,7 +48,7 @@
})
self.assertEqual(httplib.OK, response.status_code)
- self.assertNotIn('_auth_user_id', self.client.session.keys())
+ self.assertNotIn('_auth_user_id', self.client.session)
def test_logout(self):
name = factory.getRandomString()
@@ -57,7 +57,7 @@
self.client.login(username=name, password=password)
self.client.post(reverse('logout'))
- self.assertNotIn('_auth_user_id', self.client.session.keys())
+ self.assertNotIn('_auth_user_id', self.client.session)
def make_unallocated_node():
=== modified file 'src/maasserver/tests/test_forms.py'
--- src/maasserver/tests/test_forms.py 2012-02-21 13:38:03 +0000
+++ src/maasserver/tests/test_forms.py 2012-02-29 12:27:19 +0000
@@ -55,7 +55,7 @@
{'mac_addresses': ['invalid']}))
self.assertFalse(form.is_valid())
- self.assertEqual(['mac_addresses'], form.errors.keys())
+ self.assertEqual(['mac_addresses'], list(form.errors))
self.assertEqual(
['Enter a valid MAC address (e.g. AA:BB:CC:DD:EE:FF).'],
form.errors['mac_addresses'])
@@ -69,7 +69,7 @@
{'mac_addresses': ['invalid_1', 'invalid_2']}))
self.assertFalse(form.is_valid())
- self.assertEqual(['mac_addresses'], form.errors.keys())
+ self.assertEqual(['mac_addresses'], list(form.errors))
self.assertEqual(
['One or more MAC Addresses is invalid.'],
form.errors['mac_addresses'])
=== modified file 'src/maasserver/tests/test_models.py'
--- src/maasserver/tests/test_models.py 2012-02-29 10:40:06 +0000
+++ src/maasserver/tests/test_models.py 2012-02-29 12:27:19 +0000
@@ -204,7 +204,7 @@
user = factory.make_user()
available_status = NODE_STATUS.READY
unavailable_statuses = (
- set(NODE_STATUS_CHOICES_DICT.keys()) - set([available_status]))
+ set(NODE_STATUS_CHOICES_DICT) - set([available_status]))
for status in unavailable_statuses:
factory.make_node(status=status)
self.assertEqual(
=== modified file 'src/metadataserver/tests/test_fields.py'
--- src/metadataserver/tests/test_fields.py 2012-02-24 13:13:55 +0000
+++ src/metadataserver/tests/test_fields.py 2012-02-29 12:27:19 +0000
@@ -26,7 +26,7 @@
self.assertEqual(str(b"Hello"), Bin(b"Hello"))
def test_refuses_to_construct_from_unicode(self):
- self.assertRaises(AssertionError, Bin, u"Hello")
+ self.assertRaises(AssertionError, Bin, "Hello")
def test_refuses_to_construct_from_None(self):
self.assertRaises(AssertionError, Bin, None)
=== modified file 'src/provisioningserver/plugin.py'
--- src/provisioningserver/plugin.py 2012-02-15 21:12:45 +0000
+++ src/provisioningserver/plugin.py 2012-02-29 12:27:19 +0000
@@ -154,8 +154,8 @@
if broker_password is not b"test":
cb_connected = lambda ignored: None # TODO
cb_disconnected = lambda ignored: None # TODO
- cb_failed = lambda (connector, reason): (
- log.err(reason, "Connection failed"))
+ cb_failed = lambda connector_and_reason: (
+ log.err(connector_and_reason[1], "Connection failed"))
client_factory = AMQFactory(
broker_username, broker_password, broker_vhost,
cb_connected, cb_disconnected, cb_failed)
=== modified file 'src/provisioningserver/services.py'
--- src/provisioningserver/services.py 2012-02-05 14:54:02 +0000
+++ src/provisioningserver/services.py 2012-02-29 12:27:19 +0000
@@ -50,7 +50,7 @@
Service.startService(self)
if self.filename != '-':
self.logfile = LogFile.fromFullPath(
- self.filename, rotateLength=None, defaultMode=0644)
+ self.filename, rotateLength=None, defaultMode=0o644)
self.__previous_signal_handler = signal.signal(
signal.SIGUSR1, self._signal_handler)
else:
=== modified file 'src/provisioningserver/testing/amqpclient.py'
--- src/provisioningserver/testing/amqpclient.py 2012-02-15 14:23:44 +0000
+++ src/provisioningserver/testing/amqpclient.py 2012-02-29 12:27:19 +0000
@@ -128,12 +128,13 @@
factory.stopTrying()
connector.disconnect()
- def amq_connected(self, (client, channel)):
+ def amq_connected(self, client_and_channel):
"""
Save the channel and client, and fire C{self.connected_deferred}.
This is the connected_callback that's pased to the L{AMQFactory}.
"""
+ client, channel = client_and_channel
self.real_queue_declare = channel.queue_declare
channel.queue_declare = self.queue_declare
self.real_exchange_declare = channel.exchange_declare
@@ -147,10 +148,11 @@
This is the disconnected_callback that's passed to the L{AMQFactory}.
"""
- def amq_failed(self, (connector, reason)):
+ def amq_failed(self, connector_and_reason):
"""
This is the failed_callback that's passed to the L{AMQFactory}.
"""
+ connector, reason = connector_and_reason
self.connected_deferred.errback(reason)
def queue_declare(self, queue, **kwargs):
=== modified file 'src/provisioningserver/testing/fakecobbler.py'
--- src/provisioningserver/testing/fakecobbler.py 2012-02-29 10:40:06 +0000
+++ src/provisioningserver/testing/fakecobbler.py 2012-02-29 12:27:19 +0000
@@ -43,7 +43,7 @@
for ease of debugging.
"""
elements = ['token', '%s' % next(unique_ints), user, custom_id]
- return '-'.join(filter(None, elements))
+ return '-'.join(element for element in elements if element)
class FakeTwistedProxy:
@@ -511,14 +511,14 @@
token, read, self.preseed_templates, path, contents)
def get_kickstart_templates(self, token=None):
- return self.preseed_templates.keys()
+ return list(self.preseed_templates)
def read_or_write_snippet(self, path, read, contents, token):
return self._api_access_preseed(
token, read, self.preseed_snippets, path, contents)
def get_snippets(self, token=None):
- return self.preseed_snippets.keys()
+ return list(self.preseed_snippets)
def sync(self, token):
self._check_token(token)
=== modified file 'src/provisioningserver/tests/test_api.py'
--- src/provisioningserver/tests/test_api.py 2012-02-29 10:40:06 +0000
+++ src/provisioningserver/tests/test_api.py 2012-02-29 12:27:19 +0000
@@ -387,7 +387,7 @@
for num in range(3):
name = self.getUniqueString()
yield papi.add_profile(name, distro)
- expected[name] = {u'distro': u'distro', u'name': name}
+ expected[name] = {'distro': 'distro', 'name': name}
profiles = yield papi.get_profiles()
self.assertEqual(expected, profiles)
@@ -407,7 +407,7 @@
for name in node_names:
yield papi.add_node(name, profile, self.fake_metadata())
nodes = yield papi.get_nodes()
- self.assertItemsEqual(node_names, nodes.keys())
+ self.assertItemsEqual(node_names, nodes)
@inlineCallbacks
def test_get_nodes_includes_node_attributes(self):
@@ -420,7 +420,7 @@
node_name = self.getUniqueString()
yield papi.add_node(node_name, profile, self.fake_metadata())
nodes = yield papi.get_nodes()
- self.assertItemsEqual([node_name], nodes.keys())
+ self.assertItemsEqual([node_name], nodes)
self.assertIn('name', nodes[node_name])
self.assertIn('profile', nodes[node_name])
self.assertIn('mac_addresses', nodes[node_name])
=== modified file 'src/provisioningserver/tests/test_cobblersession.py'
--- src/provisioningserver/tests/test_cobblersession.py 2012-02-13 10:47:44 +0000
+++ src/provisioningserver/tests/test_cobblersession.py 2012-02-29 12:27:19 +0000
@@ -433,8 +433,8 @@
"clobber": True,
"initrd": "an_initrd",
"kernel": "a_kernel",
- "likes": u"cabbage",
- "name": u"fred",
+ "likes": "cabbage",
+ "name": "fred",
}
session.proxy.set_return_values([values_stored])
# However, CobblerObject.get_values() only returns attributes that are
@@ -458,8 +458,8 @@
{"clobber": True,
"initrd": "an_initrd",
"kernel": "a_kernel",
- "likes": u"cabbage",
- "name": u"alice"},
+ "likes": "cabbage",
+ "name": "alice"},
]
session.proxy.set_return_values([values_stored])
# However, CobblerObject.get_all_values() only returns attributes that
=== modified file 'src/provisioningserver/tests/test_plugin.py'
--- src/provisioningserver/tests/test_plugin.py 2012-02-16 09:25:28 +0000
+++ src/provisioningserver/tests/test_plugin.py 2012-02-29 12:27:19 +0000
@@ -42,7 +42,7 @@
'port': 5673,
'username': getuser(),
'password': 'test',
- 'vhost': u'/',
+ 'vhost': '/',
},
'cobbler': {
'url': 'http://localhost/cobbler_api',