← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:avoid-defer-returnValue into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:avoid-defer-returnValue into launchpad:master.

Commit message:
Stop using defer.returnValue

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/409949

On Python 3, we can just return values directly.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:avoid-defer-returnValue into launchpad:master.
diff --git a/lib/lp/buildmaster/builderproxy.py b/lib/lp/buildmaster/builderproxy.py
index aeb55c9..a224adf 100644
--- a/lib/lp/buildmaster/builderproxy.py
+++ b/lib/lp/buildmaster/builderproxy.py
@@ -74,4 +74,4 @@ class BuilderProxyMixin:
             RequestProxyTokenCommand,
             url=url, auth_header=auth_header,
             proxy_username=proxy_username)
-        defer.returnValue(token)
+        return token
diff --git a/lib/lp/buildmaster/interactor.py b/lib/lp/buildmaster/interactor.py
index 178b8d1..59f7612 100644
--- a/lib/lp/buildmaster/interactor.py
+++ b/lib/lp/buildmaster/interactor.py
@@ -424,7 +424,7 @@ class BuilderInteractor(object):
                 # apparent reason.  This could be a quirk of the Xen
                 # guest, we're not sure. See bug 586359.
                 yield slave.echo("ping")
-                defer.returnValue(True)
+                return True
             elif vitals.vm_reset_protocol == BuilderResetProtocol.PROTO_2_0:
                 # In protocol 2.0 the reset trigger is asynchronous.
                 # If the trigger succeeds we'll leave the slave in
@@ -437,7 +437,7 @@ class BuilderInteractor(object):
                     transaction.commit()
                     logger = cls._getSlaveScannerLogger()
                     logger.info("%s is being cleaned.", vitals.name)
-                defer.returnValue(False)
+                return False
             raise CannotResumeHost(
                 "Invalid vm_reset_protocol: %r" % vitals.vm_reset_protocol)
         else:
@@ -445,18 +445,18 @@ class BuilderInteractor(object):
             status = slave_status.get('builder_status', None)
             if status == 'BuilderStatus.IDLE':
                 # This is as clean as we can get it.
-                defer.returnValue(True)
+                return True
             elif status == 'BuilderStatus.BUILDING':
                 # Asynchronously abort() the slave and wait until WAITING.
                 yield slave.abort()
-                defer.returnValue(False)
+                return False
             elif status == 'BuilderStatus.ABORTING':
                 # Wait it out until WAITING.
-                defer.returnValue(False)
+                return False
             elif status == 'BuilderStatus.WAITING':
                 # Just a synchronous clean() call and we'll be idle.
                 yield slave.clean()
-                defer.returnValue(True)
+                return True
             raise BuildDaemonError(
                 "Invalid status during clean: %r" % status)
 
@@ -512,7 +512,7 @@ class BuilderInteractor(object):
                     break
         else:
             logger.debug("No build candidates available for builder.")
-            defer.returnValue(None)
+            return None
 
         new_behaviour = cls.getBuildBehaviour(candidate, builder, slave)
         needed_bfjb = type(removeSecurityProxy(
@@ -523,7 +523,7 @@ class BuilderInteractor(object):
                 (new_behaviour, needed_bfjb))
         yield cls._startBuild(
             candidate, vitals, builder, slave, new_behaviour, logger)
-        defer.returnValue(candidate)
+        return candidate
 
     @staticmethod
     def extractBuildStatus(slave_status):
diff --git a/lib/lp/buildmaster/model/buildfarmjobbehaviour.py b/lib/lp/buildmaster/model/buildfarmjobbehaviour.py
index 9cac6e9..4b5253b 100644
--- a/lib/lp/buildmaster/model/buildfarmjobbehaviour.py
+++ b/lib/lp/buildmaster/model/buildfarmjobbehaviour.py
@@ -105,9 +105,9 @@ class BuildFarmJobBehaviourBase:
     def composeBuildRequest(self, logger):
         args = yield self.extraBuildArgs(logger=logger)
         filemap = yield self.determineFilesToSend()
-        defer.returnValue(
-            (self.builder_type, self.distro_arch_series, self.pocket,
-             filemap, args))
+        return (
+            self.builder_type, self.distro_arch_series, self.pocket,
+            filemap, args)
 
     def verifyBuildRequest(self, logger):
         """The default behaviour is a no-op."""
@@ -347,7 +347,7 @@ class BuildFarmJobBehaviourBase:
         if build.job_type == BuildFarmJobType.PACKAGEBUILD:
             build = build.buildqueue_record.specific_build
             if not build.current_source_publication:
-                defer.returnValue(BuildStatus.SUPERSEDED)
+                return BuildStatus.SUPERSEDED
 
         self.verifySuccessfulBuild()
 
@@ -383,4 +383,4 @@ class BuildFarmJobBehaviourBase:
             os.mkdir(target_dir)
         os.rename(grab_dir, os.path.join(target_dir, upload_leaf))
 
-        defer.returnValue(BuildStatus.UPLOADING)
+        return BuildStatus.UPLOADING
diff --git a/lib/lp/buildmaster/tests/test_manager.py b/lib/lp/buildmaster/tests/test_manager.py
index ada37a0..0187dc2 100644
--- a/lib/lp/buildmaster/tests/test_manager.py
+++ b/lib/lp/buildmaster/tests/test_manager.py
@@ -321,7 +321,7 @@ class TestSlaveScannerScan(StatsMixin, TestCaseWithFactory):
                 status = yield super(BrokenUTF8Slave, self).status()
                 status["logtail"] = xmlrpc_client.Binary(
                     u"───".encode("UTF-8")[1:])
-                defer.returnValue(status)
+                return status
 
         builder = getUtility(IBuilderSet)[BOB_THE_BUILDER_NAME]
         login('foo.bar@xxxxxxxxxxxxx')
@@ -350,7 +350,7 @@ class TestSlaveScannerScan(StatsMixin, TestCaseWithFactory):
             def status(self):
                 status = yield super(NULSlave, self).status()
                 status["logtail"] = xmlrpc_client.Binary(b"foo\0bar\0baz")
-                defer.returnValue(status)
+                return status
 
         builder = getUtility(IBuilderSet)[BOB_THE_BUILDER_NAME]
         login('foo.bar@xxxxxxxxxxxxx')
@@ -431,7 +431,7 @@ class TestSlaveScannerScan(StatsMixin, TestCaseWithFactory):
             def status(self):
                 status = yield super(SnapBuildingSlave, self).status()
                 status["revision_id"] = self.revision_id
-                defer.returnValue(status)
+                return status
 
         build = self.factory.makeSnapBuild(
             distroarchseries=self.test_publisher.distroseries.architectures[0])
diff --git a/lib/lp/charms/model/charmrecipebuildbehaviour.py b/lib/lp/charms/model/charmrecipebuildbehaviour.py
index 99538dc..b02c90e 100644
--- a/lib/lp/charms/model/charmrecipebuildbehaviour.py
+++ b/lib/lp/charms/model/charmrecipebuildbehaviour.py
@@ -98,7 +98,7 @@ class CharmRecipeBuildBehaviour(BuilderProxyMixin, BuildFarmJobBehaviourBase):
                     build.recipe.owner.name, build.recipe.project.name,
                     build.recipe.name))
         args["private"] = build.is_private
-        defer.returnValue(args)
+        return args
 
     def verifySuccessfulBuild(self):
         """See `IBuildFarmJobBehaviour`."""
diff --git a/lib/lp/code/model/recipebuilder.py b/lib/lp/code/model/recipebuilder.py
index a40ba2c..46ef5b8 100644
--- a/lib/lp/code/model/recipebuilder.py
+++ b/lib/lp/code/model/recipebuilder.py
@@ -94,7 +94,7 @@ class RecipeBuildBehaviour(BuildFarmJobBehaviourBase):
         args['distroseries_name'] = self.build.distroseries.name
         if self.build.recipe.base_git_repository is not None:
             args['git'] = True
-        defer.returnValue(args)
+        return args
 
     def verifyBuildRequest(self, logger):
         """Assert some pre-build checks.
diff --git a/lib/lp/codehosting/sftp.py b/lib/lp/codehosting/sftp.py
index 4242a14..8e6f9cd 100644
--- a/lib/lp/codehosting/sftp.py
+++ b/lib/lp/codehosting/sftp.py
@@ -194,7 +194,7 @@ class TransportSFTPFile:
             # past the end of files, so we don't need to worry too much
             # about performance here.
             chunk = yield self.readChunk(e.offset, e.actual)
-        defer.returnValue(chunk)
+        return chunk
 
     def setAttrs(self, attrs):
         """See `ISFTPFile`.
@@ -314,7 +314,7 @@ class TransportSFTPServer:
         file_list = yield self.transport.list_dir(escaped_path)
         stat_results = yield self._stat_files_in_list(file_list, escaped_path)
         entries = self._format_directory_entries(stat_results, file_list)
-        defer.returnValue(DirectoryListing(entries))
+        return DirectoryListing(entries)
 
     @with_sftp_error
     @defer.inlineCallbacks
@@ -324,8 +324,7 @@ class TransportSFTPServer:
         directory = os.path.dirname(path)
         stat_result = yield self.transport.stat(directory)
         if stat.S_ISDIR(stat_result.st_mode):
-            defer.returnValue(
-                TransportSFTPFile(self.transport, path, flags, self))
+            return TransportSFTPFile(self.transport, path, flags, self)
         else:
             raise filetransfer.SFTPError(
                 filetransfer.FX_NO_SUCH_FILE, directory)
@@ -340,7 +339,7 @@ class TransportSFTPServer:
         relpath = self._decodePath(relpath)
         path = yield self.transport.local_realPath(urlutils.escape(relpath))
         unescaped_path = urlutils.unescape(path)
-        defer.returnValue(unescaped_path.encode('utf-8'))
+        return unescaped_path.encode('utf-8')
 
     def setAttrs(self, path, attrs):
         """See `ISFTPServer`.
@@ -374,7 +373,7 @@ class TransportSFTPServer:
         """
         path = self._decodePath(path)
         stat_result = yield self.transport.stat(urlutils.escape(path))
-        defer.returnValue(self._translate_stat(stat_result))
+        return self._translate_stat(stat_result)
 
     def gotVersion(self, otherVersion, extensionData):
         """See `ISFTPServer`."""
diff --git a/lib/lp/oci/model/ocirecipebuildbehaviour.py b/lib/lp/oci/model/ocirecipebuildbehaviour.py
index f654287..46c8569 100644
--- a/lib/lp/oci/model/ocirecipebuildbehaviour.py
+++ b/lib/lp/oci/model/ocirecipebuildbehaviour.py
@@ -169,7 +169,7 @@ class OCIRecipeBuildBehaviour(BuilderProxyMixin, BuildFarmJobBehaviourBase):
         if build.recipe.git_path != "HEAD":
             args["git_path"] = build.recipe.git_ref.name
 
-        defer.returnValue(args)
+        return args
 
     def _ensureFilePath(self, file_name, file_path, upload_path):
         # If the evaluated output file name is not within our
@@ -187,8 +187,7 @@ class OCIRecipeBuildBehaviour(BuilderProxyMixin, BuildFarmJobBehaviourBase):
         yield self._slave.getFile(file_hash, file_path)
 
         with open(file_path, 'r') as file_fp:
-            contents = json.load(file_fp)
-        defer.returnValue(contents)
+            return json.load(file_fp)
 
     def _extractLayerFiles(self, upload_path, section, config, digests, files):
         # These are different sets of ids, in the same order
diff --git a/lib/lp/services/librarianserver/db.py b/lib/lp/services/librarianserver/db.py
index df53941..972ca8f 100644
--- a/lib/lp/services/librarianserver/db.py
+++ b/lib/lp/services/librarianserver/db.py
@@ -76,10 +76,10 @@ class Library:
                     "verifyMacaroon", macaroon.serialize(), "LibraryFileAlias",
                     aliasid),
                 config.librarian.authentication_timeout)
-            defer.returnValue(True)
+            return True
         except Fault as fault:
             if fault.faultCode == faults.Unauthorized.error_code:
-                defer.returnValue(False)
+                return False
             else:
                 raise
 
diff --git a/lib/lp/services/librarianserver/storage.py b/lib/lp/services/librarianserver/storage.py
index 9554dbb..e8611b2 100644
--- a/lib/lp/services/librarianserver/storage.py
+++ b/lib/lp/services/librarianserver/storage.py
@@ -130,9 +130,8 @@ class LibrarianStorage:
                     headers, chunks = yield deferToThread(
                         swift.quiet_swiftclient, swift_connection.get_object,
                         container, name, resp_chunk_size=self.CHUNK_SIZE)
-                    swift_stream = TxSwiftStream(
+                    return TxSwiftStream(
                         connection_pool, swift_connection, chunks)
-                    defer.returnValue(swift_stream)
                 except swiftclient.ClientException as x:
                     if x.http_status == 404:
                         connection_pool.put(swift_connection)
@@ -151,7 +150,7 @@ class LibrarianStorage:
 
         path = self._fileLocation(fileid)
         if os.path.exists(path):
-            defer.returnValue(open(path, 'rb'))
+            return open(path, 'rb')
 
     def _fileLocation(self, fileid):
         return os.path.join(self.directory, _relFileLocation(str(fileid)))
@@ -170,10 +169,10 @@ class TxSwiftStream(swift.SwiftStream):
             raise ValueError('I/O operation on closed file')
 
         if self._swift_connection is None:
-            defer.returnValue(b'')  # EOF already reached, connection returned.
+            return b''  # EOF already reached, connection returned.
 
         if size == 0:
-            defer.returnValue(b'')
+            return b''
 
         if not self._chunk:
             self._chunk = yield deferToThread(self._next_chunk)
@@ -185,12 +184,12 @@ class TxSwiftStream(swift.SwiftStream):
                     self._connection_pool.put(self._swift_connection)
                     self._swift_connection = None
                 self._chunks = None
-                defer.returnValue(b'')
+                return b''
         return_chunk = self._chunk[:size]
         self._chunk = self._chunk[size:]
 
         self._offset += len(return_chunk)
-        defer.returnValue(return_chunk)
+        return return_chunk
 
 
 class LibraryFileUpload(object):
diff --git a/lib/lp/services/librarianserver/web.py b/lib/lp/services/librarianserver/web.py
index 3d567ab..55ad829 100644
--- a/lib/lp/services/librarianserver/web.py
+++ b/lib/lp/services/librarianserver/web.py
@@ -172,7 +172,7 @@ class LibraryFileAliasResource(resource.Resource):
             log.msg(
                 "404: dbfilename.encode('utf-8') != filename: %r != %r"
                 % (dbfilename.encode('utf-8'), filename))
-            defer.returnValue(fourOhFour)
+            return fourOhFour
 
         stream = yield self.storage.open(dbcontentID)
         if stream is not None:
@@ -186,11 +186,10 @@ class LibraryFileAliasResource(resource.Resource):
                 'Cache-Control',
                 'max-age=31536000, public'
                 if not restricted else 'max-age=0, private')
-            defer.returnValue(file)
+            return file
         elif self.upstreamHost is not None:
-            defer.returnValue(
-                proxy.ReverseProxyResource(
-                    self.upstreamHost, self.upstreamPort, request.path))
+            return proxy.ReverseProxyResource(
+                self.upstreamHost, self.upstreamPort, request.path)
         else:
             raise AssertionError(
                 "Content %d missing from storage." % dbcontentID)
diff --git a/lib/lp/snappy/model/snapbuildbehaviour.py b/lib/lp/snappy/model/snapbuildbehaviour.py
index 69adcfe..cfbf645 100644
--- a/lib/lp/snappy/model/snapbuildbehaviour.py
+++ b/lib/lp/snappy/model/snapbuildbehaviour.py
@@ -166,7 +166,7 @@ class SnapBuildBehaviour(BuilderProxyMixin, BuildFarmJobBehaviourBase):
             # (matching snapd, SAS and snapcraft representation)
             timestamp = format_as_rfc3339(build_request.date_requested)
             args["build_request_timestamp"] = timestamp
-        defer.returnValue(args)
+        return args
 
     def verifySuccessfulBuild(self):
         """See `IBuildFarmJobBehaviour`."""
diff --git a/lib/lp/soyuz/adapters/archivedependencies.py b/lib/lp/soyuz/adapters/archivedependencies.py
index c19dca9..27ae3e3 100644
--- a/lib/lp/soyuz/adapters/archivedependencies.py
+++ b/lib/lp/soyuz/adapters/archivedependencies.py
@@ -325,9 +325,9 @@ def get_sources_list_for_building(behaviour, distroarchseries,
     # binaries that need to override primary binaries of the same
     # version), we want the external dependency lines to show up second:
     # after the archive itself, but before any other dependencies.
-    defer.returnValue(
-        ([sources_list_lines[0]] + external_dep_lines + sources_list_lines[1:],
-         trusted_keys))
+    return (
+        [sources_list_lines[0]] + external_dep_lines + sources_list_lines[1:],
+        trusted_keys)
 
 
 def _has_published_binaries(archive, distroarchseries, pocket):
@@ -358,7 +358,7 @@ def _get_binary_sources_list_line(behaviour, archive, distroarchseries, pocket,
         url = archive.archive_url
 
     suite = distroarchseries.distroseries.name + pocketsuffix[pocket]
-    defer.returnValue('deb %s %s %s' % (url, suite, ' '.join(components)))
+    return 'deb %s %s %s' % (url, suite, ' '.join(components))
 
 
 @defer.inlineCallbacks
@@ -423,8 +423,7 @@ def _get_sources_list_for_dependencies(behaviour, dependencies, logger=None):
                 trusted_keys[fingerprint] = (
                     base64.b64encode(key.export()).decode("ASCII"))
 
-    defer.returnValue(
-        (sources_list_lines, [v for k, v in sorted(trusted_keys.items())]))
+    return (sources_list_lines, [v for k, v in sorted(trusted_keys.items())])
 
 
 def _get_default_primary_dependencies(archive, distro_arch_series, component,
diff --git a/lib/lp/soyuz/adapters/tests/test_archivedependencies.py b/lib/lp/soyuz/adapters/tests/test_archivedependencies.py
index bf9bec5..a6374a5 100644
--- a/lib/lp/soyuz/adapters/tests/test_archivedependencies.py
+++ b/lib/lp/soyuz/adapters/tests/test_archivedependencies.py
@@ -178,7 +178,7 @@ class TestSourcesList(TestCaseWithFactory):
         if publish_binary:
             self.publisher.getPubBinaries(
                 archive=archive, status=PackagePublishingStatus.PUBLISHED)
-        defer.returnValue(archive)
+        return archive
 
     def makeBuild(self, **kwargs):
         pub_source = self.publisher.getPubSource(**kwargs)
diff --git a/lib/lp/soyuz/model/binarypackagebuildbehaviour.py b/lib/lp/soyuz/model/binarypackagebuildbehaviour.py
index 287f66b..fc94d9a 100644
--- a/lib/lp/soyuz/model/binarypackagebuildbehaviour.py
+++ b/lib/lp/soyuz/model/binarypackagebuildbehaviour.py
@@ -89,7 +89,7 @@ class BinaryPackageBuildBehaviour(BuildFarmJobBehaviourBase):
                     'url': urlappend(pool_url, lfa.filename),
                     'username': 'buildd',
                     'password': macaroon_raw}
-        defer.returnValue(filemap)
+        return filemap
 
     def verifyBuildRequest(self, logger):
         """Assert some pre-build checks.
@@ -180,4 +180,4 @@ class BinaryPackageBuildBehaviour(BuildFarmJobBehaviourBase):
                 self, das, build.source_package_release.name, logger=logger))
         args['build_debug_symbols'] = build.archive.build_debug_symbols
 
-        defer.returnValue(args)
+        return args
diff --git a/lib/lp/soyuz/model/livefsbuildbehaviour.py b/lib/lp/soyuz/model/livefsbuildbehaviour.py
index be29688..acf8999 100644
--- a/lib/lp/soyuz/model/livefsbuildbehaviour.py
+++ b/lib/lp/soyuz/model/livefsbuildbehaviour.py
@@ -107,7 +107,7 @@ class LiveFSBuildBehaviour(BuildFarmJobBehaviourBase):
         args["archives"], args["trusted_keys"] = (
             yield get_sources_list_for_building(
                 self, build.distro_arch_series, None, logger=logger))
-        defer.returnValue(args)
+        return args
 
     def verifySuccessfulBuild(self):
         """See `IBuildFarmJobBehaviour`."""
diff --git a/lib/lp/soyuz/tests/test_binarypackagebuildbehaviour.py b/lib/lp/soyuz/tests/test_binarypackagebuildbehaviour.py
index 3fa99d4..5239946 100644
--- a/lib/lp/soyuz/tests/test_binarypackagebuildbehaviour.py
+++ b/lib/lp/soyuz/tests/test_binarypackagebuildbehaviour.py
@@ -165,10 +165,9 @@ class TestBinaryBuildPackageBehaviour(StatsMixin, TestCaseWithFactory):
         build_log = [
             ('build', build.build_cookie, 'binarypackage',
              chroot.content.sha1, filemap_names, extra_args)]
-        result = MatchesListwise([
+        return MatchesListwise([
             item if hasattr(item, 'match') else Equals(item)
             for item in upload_logs + build_log])
-        defer.returnValue(result)
 
     @defer.inlineCallbacks
     def test_non_virtual_ppa_dispatch(self):
diff --git a/lib/lp/testing/keyserver/inprocess.py b/lib/lp/testing/keyserver/inprocess.py
index ef4a54c..70d6aae 100644
--- a/lib/lp/testing/keyserver/inprocess.py
+++ b/lib/lp/testing/keyserver/inprocess.py
@@ -67,8 +67,7 @@ class InProcessKeyServerFixture(Fixture):
         # fixtures.callmany.CallMany doesn't support cleanup functions that
         # return Deferred, so we have to do this manually.
         yield self._port.stopListening()
-        defer.returnValue(
-            super(InProcessKeyServerFixture, self).cleanUp(*args, **kwargs))
+        return super(InProcessKeyServerFixture, self).cleanUp(*args, **kwargs)
 
     @property
     def url(self):
diff --git a/lib/lp/translations/model/translationtemplatesbuildbehaviour.py b/lib/lp/translations/model/translationtemplatesbuildbehaviour.py
index a2a82fc..f141c87 100644
--- a/lib/lp/translations/model/translationtemplatesbuildbehaviour.py
+++ b/lib/lp/translations/model/translationtemplatesbuildbehaviour.py
@@ -133,4 +133,4 @@ class TranslationTemplatesBuildBehaviour(BuildFarmJobBehaviourBase):
             finally:
                 tarball_file.close()
                 os.remove(filename)
-        defer.returnValue(BuildStatus.FULLYBUILT)
+        return BuildStatus.FULLYBUILT