launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #22120
[Merge] lp:~cjwatson/launchpad/pep-3113 into lp:launchpad
Colin Watson has proposed merging lp:~cjwatson/launchpad/pep-3113 into lp:launchpad.
Commit message:
Avoid relying on tuple parameter unpacking.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/pep-3113/+merge/336686
This syntax was abolished in Python 3.0 by PEP 3113.
--
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~cjwatson/launchpad/pep-3113 into lp:launchpad.
=== modified file 'lib/lp/blueprints/browser/specification.py'
--- lib/lp/blueprints/browser/specification.py 2015-01-07 00:16:33 +0000
+++ lib/lp/blueprints/browser/specification.py 2018-01-26 14:41:43 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009-2013 Canonical Ltd. This software is licensed under the
+# Copyright 2009-2018 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""Specification views."""
@@ -1206,7 +1206,7 @@
An edge is a tuple (from_node, to_node).
"""
return sorted(self.edges,
- key=lambda (from_node, to_node): (from_node.name, to_node.name))
+ key=lambda nodes: (nodes[0].name, nodes[1].name))
def listNodes(self):
"""Return a string of diagnostic output of nodes and edges.
=== modified file 'lib/lp/bugs/model/tests/test_bugsubscriptioninfo.py'
--- lib/lp/bugs/model/tests/test_bugsubscriptioninfo.py 2012-08-16 05:18:54 +0000
+++ lib/lp/bugs/model/tests/test_bugsubscriptioninfo.py 2018-01-26 14:41:43 +0000
@@ -1,4 +1,4 @@
-# Copyright 2010-2012 Canonical Ltd. This software is licensed under the
+# Copyright 2010-2018 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""Test `BugSubscriptionInfo`."""
@@ -59,10 +59,10 @@
def setUp(self):
super(TestSubscriptionRelatedSets, self).setUp()
- make_person = lambda (displayname, name): (
+ make_person = lambda displayname, name: (
self.factory.makePerson(displayname=displayname, name=name))
subscribers = dict(
- (name_pair, make_person(name_pair))
+ (name_pair, make_person(*name_pair))
for name_pair in self.name_pairs)
self.subscribers_set = frozenset(subscribers.itervalues())
self.subscribers_sorted = tuple(
=== modified file 'lib/lp/bugs/scripts/bugsummaryrebuild.py'
--- lib/lp/bugs/scripts/bugsummaryrebuild.py 2013-06-20 05:50:00 +0000
+++ lib/lp/bugs/scripts/bugsummaryrebuild.py 2018-01-26 14:41:43 +0000
@@ -1,4 +1,4 @@
-# Copyright 2012 Canonical Ltd. This software is licensed under the
+# Copyright 2012-2018 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
__metaclass__ = type
@@ -81,7 +81,9 @@
def load_target(pid, psid, did, dsid, spnid):
store = IStore(Product)
p, ps, d, ds, spn = map(
- lambda (cls, id): store.get(cls, id) if id is not None else None,
+ lambda cls_id: (
+ store.get(cls_id[0], cls_id[1]) if cls_id[1] is not None
+ else None),
zip((Product, ProductSeries, Distribution, DistroSeries,
SourcePackageName),
(pid, psid, did, dsid, spnid)))
@@ -205,7 +207,7 @@
chunk = removed[:100]
removed = removed[100:]
exprs = [
- map(lambda (k, v): k == v, zip(key_cols, key))
+ map(lambda k_v: k_v[0] == k_v[1], zip(key_cols, key))
for key in chunk]
IStore(RawBugSummary).find(
RawBugSummary,
=== modified file 'lib/lp/buildmaster/interactor.py'
--- lib/lp/buildmaster/interactor.py 2017-04-27 15:54:54 +0000
+++ lib/lp/buildmaster/interactor.py 2018-01-26 14:41:43 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009-2017 Canonical Ltd. This software is licensed under the
+# Copyright 2009-2018 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
__metaclass__ = type
@@ -379,7 +379,8 @@
d = slave.resume()
- def got_resume_ok((stdout, stderr, returncode)):
+ def got_resume_ok(args):
+ stdout, stderr, returncode = args
return stdout, stderr
def got_resume_bad(failure):
=== modified file 'lib/lp/buildmaster/tests/mock_slaves.py'
--- lib/lp/buildmaster/tests/mock_slaves.py 2017-09-13 08:06:56 +0000
+++ lib/lp/buildmaster/tests/mock_slaves.py 2018-01-26 14:41:43 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009-2017 Canonical Ltd. This software is licensed under the
+# Copyright 2009-2018 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""Mock Build objects for tests soyuz buildd-system."""
@@ -127,15 +127,12 @@
self.call_log.append('resume')
return defer.succeed(("", "", 0))
+ @defer.inlineCallbacks
def sendFileToSlave(self, sha1, url, username="", password="",
logger=None):
- d = self.ensurepresent(sha1, url, username, password)
-
- def check_present((present, info)):
- if not present:
- raise CannotFetchFile(url, info)
-
- return d.addCallback(check_present)
+ present, info = yield self.ensurepresent(sha1, url, username, password)
+ if not present:
+ raise CannotFetchFile(url, info)
def getURL(self, sha1):
return urlappend(
=== modified file 'lib/lp/codehosting/puller/tests/test_scheduler.py'
--- lib/lp/codehosting/puller/tests/test_scheduler.py 2018-01-02 10:54:31 +0000
+++ lib/lp/codehosting/puller/tests/test_scheduler.py 2018-01-26 14:41:43 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009-2011 Canonical Ltd. This software is licensed under the
+# Copyright 2009-2018 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
__metaclass__ = type
@@ -649,8 +649,8 @@
# contents of stderr are logged in an OOPS report.
oops_logged = []
- def new_oops_raising((type, value, tb), request):
- oops_logged.append((type, value, tb))
+ def new_oops_raising(info, request):
+ oops_logged.append(info)
old_oops_raising = errorlog.globalErrorUtility.raising
errorlog.globalErrorUtility.raising = new_oops_raising
=== modified file 'lib/lp/codehosting/vfs/branchfs.py'
--- lib/lp/codehosting/vfs/branchfs.py 2015-07-08 16:05:11 +0000
+++ lib/lp/codehosting/vfs/branchfs.py 2018-01-26 14:41:43 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009 Canonical Ltd. This software is licensed under the
+# Copyright 2009-2018 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""The Launchpad code hosting file system.
@@ -466,7 +466,8 @@
virtual_url_fragment.lstrip('/')))
@no_traceback_failures
- def process_result((branch, trailing)):
+ def process_result(result):
+ branch, trailing = result
if branch is None:
raise NoSuchFile(virtual_url_fragment)
else:
@@ -494,7 +495,7 @@
# the user tries to make a directory like "~foo/bar". That is, a
# directory that has too little information to be translated into a
# Launchpad branch.
- deferred = AsyncVirtualTransport._getUnderylingTransportAndPath(
+ deferred = AsyncVirtualTransport._getUnderlyingTransportAndPath(
self, relpath)
@no_traceback_failures
@@ -504,7 +505,8 @@
return self.server.createBranch(self._abspath(relpath))
@no_traceback_failures
- def real_mkdir((transport, path)):
+ def real_mkdir(result):
+ transport, path = result
return getattr(transport, 'mkdir')(path, mode)
deferred.addCallback(real_mkdir)
@@ -663,7 +665,8 @@
'/' + virtual_url_fragment)
@no_traceback_failures
- def got_path_info((transport_type, data, trailing_path)):
+ def got_path_info(result):
+ transport_type, data, trailing_path = result
if transport_type != BRANCH_TRANSPORT:
raise NotABranchPath(virtual_url_fragment)
transport, _ = self._transport_dispatch.makeTransport(
=== modified file 'lib/lp/codehosting/vfs/tests/test_branchfs.py'
--- lib/lp/codehosting/vfs/tests/test_branchfs.py 2013-08-16 05:16:44 +0000
+++ lib/lp/codehosting/vfs/tests/test_branchfs.py 2018-01-26 14:41:43 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009-2010 Canonical Ltd. This software is licensed under the
+# Copyright 2009-2018 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""Tests for the branch filesystem."""
@@ -254,19 +254,18 @@
return LaunchpadServer(
XMLRPCWrapper(codehosting_api), user_id, MemoryTransport())
+ @defer.inlineCallbacks
def test_translateControlPath(self):
branch = self.factory.makeProductBranch(owner=self.requester)
self.factory.enableDefaultStackingForProduct(branch.product, branch)
- deferred = self.server.translateVirtualPath(
+ transport, path = yield self.server.translateVirtualPath(
'~%s/%s/.bzr/control.conf'
% (branch.owner.name, branch.product.name))
-
- def check_control_file((transport, path)):
- self.assertEqual(
- 'default_stack_on = %s\n' % branch_id_alias(branch),
- transport.get_bytes(path))
- return deferred.addCallback(check_control_file)
-
+ self.assertEqual(
+ 'default_stack_on = %s\n' % branch_id_alias(branch),
+ transport.get_bytes(path))
+
+ @defer.inlineCallbacks
def test_translate_branch_path_hosted(self):
# translateVirtualPath returns a writable transport like that returned
# by TransportDispatch.makeTransport for branches we can write to.
@@ -277,30 +276,25 @@
'.bzr/README'))
expected_transport, expected_path = dispatch
- deferred = self.server.translateVirtualPath(
+ transport, path = yield self.server.translateVirtualPath(
'%s/.bzr/README' % (branch.unique_name,))
-
- def check_branch_transport((transport, path)):
- self.assertEqual(expected_path, path)
- # Can't test for equality of transports, since URLs and object
- # identity differ.
- file_data = self.factory.getUniqueString()
- transport.mkdir(os.path.dirname(path))
- transport.put_bytes(path, file_data)
- self.assertEqual(file_data, expected_transport.get_bytes(path))
- return deferred.addCallback(check_branch_transport)
-
+ self.assertEqual(expected_path, path)
+ # Can't test for equality of transports, since URLs and object
+ # identity differ.
+ file_data = self.factory.getUniqueString()
+ transport.mkdir(os.path.dirname(path))
+ transport.put_bytes(path, file_data)
+ self.assertEqual(file_data, expected_transport.get_bytes(path))
+
+ @defer.inlineCallbacks
def test_translate_branch_path_mirrored(self):
# translateVirtualPath returns a read-only transport for branches we
# can't write to.
branch = self.factory.makeAnyBranch(branch_type=BranchType.HOSTED)
- deferred = self.server.translateVirtualPath(
+ transport, path = yield self.server.translateVirtualPath(
'%s/.bzr/README' % (branch.unique_name,))
-
- def check_branch_transport((transport, path)):
- self.assertEqual('.bzr/README', path)
- self.assertEqual(True, transport.is_readonly())
- return deferred.addCallback(check_branch_transport)
+ self.assertEqual('.bzr/README', path)
+ self.assertEqual(True, transport.is_readonly())
def test_createBranch_error_translation(self):
# createBranch raises PermissionDenied if we try to create a branch
@@ -328,6 +322,7 @@
class LaunchpadInternalServerTests:
"""Tests for the internal server classes, used by e.g. the scanner."""
+ @defer.inlineCallbacks
def test_translate_branch_path(self):
branch = self.factory.makeAnyBranch()
dispatch = self.server._transport_dispatch.makeTransport((
@@ -335,18 +330,15 @@
'.bzr/README'))
expected_transport, expected_path = dispatch
- deferred = self.server.translateVirtualPath(
+ transport, path = yield self.server.translateVirtualPath(
'/%s/.bzr/README' % (branch.unique_name,))
-
- def check_branch_transport((transport, path)):
- self.assertEqual(expected_path, path)
- # Can't test for equality of transports, since URLs and object
- # identity differ.
- file_data = self.factory.getUniqueString()
- transport.mkdir(os.path.dirname(path))
- transport.put_bytes(path, file_data)
- self.assertEqual(file_data, expected_transport.get_bytes(path))
- return deferred.addCallback(check_branch_transport)
+ self.assertEqual(expected_path, path)
+ # Can't test for equality of transports, since URLs and object
+ # identity differ.
+ file_data = self.factory.getUniqueString()
+ transport.mkdir(os.path.dirname(path))
+ transport.put_bytes(path, file_data)
+ self.assertEqual(file_data, expected_transport.get_bytes(path))
def test_translate_control_dir_path(self):
self.server.start_server()
=== modified file 'lib/lp/codehosting/vfs/tests/test_branchfsclient.py'
--- lib/lp/codehosting/vfs/tests/test_branchfsclient.py 2015-10-19 10:56:16 +0000
+++ lib/lp/codehosting/vfs/tests/test_branchfsclient.py 2018-01-26 14:41:43 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009-2010 Canonical Ltd. This software is licensed under the
+# Copyright 2009-2018 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""Tests for branchfsclient."""
@@ -6,6 +6,7 @@
__metaclass__ = type
from testtools.deferredruntest import AsynchronousDeferredRunTest
+from twisted.internet import defer
from lp.code.interfaces.codehosting import BRANCH_TRANSPORT
from lp.codehosting.inmemory import (
@@ -160,6 +161,7 @@
self.assertRaises(
NotInCache, client._getFromCache, "foo")
+ @defer.inlineCallbacks
def test_translatePath_retrieves_from_cache(self):
# If the path already has a prefix in the cache, we use that prefix to
# translate the path.
@@ -171,14 +173,11 @@
client._addToCache(
(BRANCH_TRANSPORT, fake_data, ''), '/%s' % branch.unique_name)
requested_path = '/%s/foo/bar' % branch.unique_name
- deferred = client.translatePath(requested_path)
-
- def path_translated((transport_type, data, trailing_path)):
- self.assertEqual(BRANCH_TRANSPORT, transport_type)
- self.assertEqual(fake_data, data)
- self.assertEqual('foo/bar', trailing_path)
-
- return deferred.addCallback(path_translated)
+ transport_type, data, trailing_path = yield client.translatePath(
+ requested_path)
+ self.assertEqual(BRANCH_TRANSPORT, transport_type)
+ self.assertEqual(fake_data, data)
+ self.assertEqual('foo/bar', trailing_path)
def test_translatePath_adds_to_cache(self):
# translatePath adds successful path translations to the cache, thus
@@ -191,25 +190,19 @@
client._getFromCache('/' + branch.unique_name))
return deferred
+ @defer.inlineCallbacks
def test_translatePath_control_branch_cache_interaction(self):
# We don't want the caching to make us mis-interpret paths in the
# branch as paths into the control transport.
branch = self.factory.makeAnyBranch()
client = self.makeClient()
self.factory.enableDefaultStackingForProduct(branch.product)
- deferred = client.translatePath(
+ yield client.translatePath(
'/~' + branch.owner.name + '/' + branch.product.name +
'/.bzr/format')
-
- def call_translatePath_again(ignored):
- return client.translatePath('/' + branch.unique_name)
-
- def check_results((transport_type, data, trailing_path)):
- self.assertEqual(BRANCH_TRANSPORT, transport_type)
-
- deferred.addCallback(call_translatePath_again)
- deferred.addCallback(check_results)
- return deferred
+ transport_type, data, trailing_path = yield client.translatePath(
+ '/' + branch.unique_name)
+ self.assertEqual(BRANCH_TRANSPORT, transport_type)
def test_errors_not_cached(self):
# Don't cache failed translations. What would be the point?
=== modified file 'lib/lp/codehosting/vfs/transport.py'
--- lib/lp/codehosting/vfs/transport.py 2015-10-19 10:56:16 +0000
+++ lib/lp/codehosting/vfs/transport.py 2018-01-26 14:41:43 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009 Canonical Ltd. This software is licensed under the
+# Copyright 2009-2018 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""Transport utilities for the codehosting system.
@@ -102,7 +102,7 @@
return urlutils.joinpath(
self.base[len(self.server.get_url()) - 1:], relpath)
- def _getUnderylingTransportAndPath(self, relpath):
+ def _getUnderlyingTransportAndPath(self, relpath):
"""Return the underlying transport and path for `relpath`."""
virtual_url_fragment = self._abspath(relpath)
return self.server.translateVirtualPath(virtual_url_fragment)
@@ -129,7 +129,8 @@
then the method will be called on the backing transport decorated with
'readonly+'.
"""
- def call_method((transport, path)):
+ def call_method(result):
+ transport, path = result
method = getattr(transport, method_name)
try:
return method(path, *args, **kwargs)
@@ -140,7 +141,7 @@
# stringification on it.
return Failure(e)
- deferred = self._getUnderylingTransportAndPath(relpath)
+ deferred = self._getUnderlyingTransportAndPath(relpath)
deferred.addCallback(call_method)
deferred.addErrback(self._translateError)
return deferred
@@ -175,20 +176,22 @@
return self._call('has', relpath)
def iter_files_recursive(self):
- deferred = self._getUnderylingTransportAndPath('.')
+ deferred = self._getUnderlyingTransportAndPath('.')
@no_traceback_failures
- def iter_files((transport, path)):
+ def iter_files(result):
+ transport, path = result
return transport.clone(path).iter_files_recursive()
deferred.addCallback(iter_files)
return deferred
def listable(self):
- deferred = self._getUnderylingTransportAndPath('.')
+ deferred = self._getUnderlyingTransportAndPath('.')
@no_traceback_failures
- def listable((transport, path)):
+ def listable(result):
+ transport, path = result
return transport.listable()
deferred.addCallback(listable)
@@ -228,8 +231,8 @@
'readv', relpath, offsets, adjust_for_latency, upper_limit)
def rename(self, rel_from, rel_to):
- to_deferred = self._getUnderylingTransportAndPath(rel_to)
- from_deferred = self._getUnderylingTransportAndPath(rel_from)
+ to_deferred = self._getUnderlyingTransportAndPath(rel_to)
+ from_deferred = self._getUnderlyingTransportAndPath(rel_from)
deferred = gatherResults([to_deferred, from_deferred])
@no_traceback_failures
=== modified file 'lib/lp/registry/model/distroseries.py'
--- lib/lp/registry/model/distroseries.py 2017-03-29 09:28:09 +0000
+++ lib/lp/registry/model/distroseries.py 2018-01-26 14:41:43 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009-2017 Canonical Ltd. This software is licensed under the
+# Copyright 2009-2018 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""Database classes for a distribution series."""
@@ -1258,7 +1258,8 @@
# Create a function that will decorate the results, converting
# them from the find_spec above into a DSBP:
- def result_to_dsbp((cache, binary_package_name, rank)):
+ def result_to_dsbp(row):
+ cache, binary_package_name, rank = row
return DistroSeriesBinaryPackage(
distroseries=cache.distroseries,
binarypackagename=binary_package_name,
=== modified file 'lib/lp/services/helpers.py'
--- lib/lp/services/helpers.py 2016-03-17 14:47:14 +0000
+++ lib/lp/services/helpers.py 2018-01-26 14:41:43 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009-2014 Canonical Ltd. This software is licensed under the
+# Copyright 2009-2018 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""Various functions and classes that are useful across different parts of
@@ -61,7 +61,7 @@
list_item = '(%s)'
join_char = '|'
for find, replace in sorted(replacements.items(),
- key=lambda (key, value): len(key),
+ key=lambda item: len(item[0]),
reverse=True):
L.append(list_item % re.escape(find))
# Make a copy of the replacements dict, as it is mutable, but we're
=== modified file 'lib/lp/services/librarianserver/libraryprotocol.py'
--- lib/lp/services/librarianserver/libraryprotocol.py 2012-06-29 08:40:05 +0000
+++ lib/lp/services/librarianserver/libraryprotocol.py 2018-01-26 14:41:43 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009-2011 Canonical Ltd. This software is licensed under the
+# Copyright 2009-2018 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
__metaclass__ = type
@@ -211,8 +211,9 @@
# Store file.
deferred = self._storeFile()
- def _sendID((fileID, aliasID)):
+ def _sendID(ids):
# Send ID to client.
+ fileID, aliasID = ids
if self.newFile.contentID is None:
# Respond with deprecated server-generated IDs.
self.sendLine('200 %s/%s' % (fileID, aliasID))
=== modified file 'utilities/generate-external-bug-status-docs'
--- utilities/generate-external-bug-status-docs 2012-01-01 03:10:25 +0000
+++ utilities/generate-external-bug-status-docs 2018-01-26 14:41:43 +0000
@@ -1,6 +1,6 @@
#!/usr/bin/python -S
#
-# Copyright 2009 Canonical Ltd. This software is licensed under the
+# Copyright 2009-2018 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
#
# Generates documentation of mapping from remote bug tracker statuses
@@ -94,7 +94,7 @@
"""Generate all the tables."""
documentable_classes = sorted(
generate_documentable_classes(),
- key=(lambda (typ, cls): typ.title))
+ key=(lambda typ_cls: typ_cls[0].title))
return chain(
*(chain(generate_table(typ, cls),
generate_blank_lines(2))
Follow ups