← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:flake8-assigned-never-used into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:flake8-assigned-never-used into launchpad:master.

Commit message:
flake8: Fix assigned-but-never-used local variables

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

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

Most of these are trivial.  In the case of `utilities/paste`, neither paste.ubuntu.com nor pastebin.canonical.com supports a `title` parameter, so I just dropped that.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:flake8-assigned-never-used into launchpad:master.
diff --git a/lib/lp/app/browser/launchpad.py b/lib/lp/app/browser/launchpad.py
index 5ab3e0c..af75881 100644
--- a/lib/lp/app/browser/launchpad.py
+++ b/lib/lp/app/browser/launchpad.py
@@ -747,7 +747,7 @@ class LaunchpadRootNavigation(Navigation):
             target_url = canonical_url(branch, request=self.request)
             if trailing != '':
                 target_url = urlappend(target_url, trailing)
-        except (NoLinkedBranch) as e:
+        except NoLinkedBranch:
             # A valid ICanHasLinkedBranch target exists but there's no
             # branch or it's not visible.
 
diff --git a/lib/lp/archiveuploader/dscfile.py b/lib/lp/archiveuploader/dscfile.py
index 9140ef4..369f8d9 100644
--- a/lib/lp/archiveuploader/dscfile.py
+++ b/lib/lp/archiveuploader/dscfile.py
@@ -536,7 +536,7 @@ class DSCFile(SourceUploadFile, SignableTagFile):
             try:
                 library_file, file_archive = self._getFileByName(
                     sub_dsc_file.filename)
-            except NotFoundError as error:
+            except NotFoundError:
                 library_file = None
                 file_archive = None
             else:
diff --git a/lib/lp/bugs/browser/widgets/bugtask.py b/lib/lp/bugs/browser/widgets/bugtask.py
index a690d72..6c1ec15 100644
--- a/lib/lp/bugs/browser/widgets/bugtask.py
+++ b/lib/lp/bugs/browser/widgets/bugtask.py
@@ -336,7 +336,7 @@ class BugTaskBugWatchWidget(RadioWidget):
                 raise WidgetInputError(
                     self.context.__name__, self.label,
                     'Remote Bug: %s' % error.doc())
-            except (NoBugTrackerFound, UnrecognizedBugTrackerURL) as error:
+            except (NoBugTrackerFound, UnrecognizedBugTrackerURL):
                 raise WidgetInputError(
                     self.context.__name__, self.label,
                     'Invalid bug tracker URL.')
diff --git a/lib/lp/codehosting/puller/worker.py b/lib/lp/codehosting/puller/worker.py
index 0b1ac31..aa9f21d 100644
--- a/lib/lp/codehosting/puller/worker.py
+++ b/lib/lp/codehosting/puller/worker.py
@@ -406,7 +406,7 @@ class PullerWorker:
             msg = 'A socket error occurred: %s' % str(e)
             self._mirrorFailed(msg)
 
-        except errors.UnsupportedFormatError as e:
+        except errors.UnsupportedFormatError:
             msg = ("Launchpad does not support branches from before "
                    "bzr 0.7. Please upgrade the branch using bzr upgrade.")
             self._mirrorFailed(msg)
@@ -414,7 +414,7 @@ class PullerWorker:
         except errors.UnknownFormatError as e:
             self._mirrorFailed(e)
 
-        except (errors.ParamikoNotPresent, BadUrlSsh) as e:
+        except (errors.ParamikoNotPresent, BadUrlSsh):
             msg = ("Launchpad cannot mirror branches from SFTP and SSH URLs."
                    " Please register a HTTP location for this branch.")
             self._mirrorFailed(msg)
@@ -437,12 +437,12 @@ class PullerWorker:
             msg = message_by_type.get(self.branch_type, str(e))
             self._mirrorFailed(msg)
 
-        except BranchReferenceForbidden as e:
+        except BranchReferenceForbidden:
             msg = ("Branch references are not allowed for branches of type "
                    "%s." % (self.branch_type.title,))
             self._mirrorFailed(msg)
 
-        except BranchLoopError as e:
+        except BranchLoopError:
             msg = "Circular branch reference."
             self._mirrorFailed(msg)
 
diff --git a/lib/lp/registry/scripts/distributionmirror_prober.py b/lib/lp/registry/scripts/distributionmirror_prober.py
index 008c56b..5530c5a 100644
--- a/lib/lp/registry/scripts/distributionmirror_prober.py
+++ b/lib/lp/registry/scripts/distributionmirror_prober.py
@@ -483,7 +483,7 @@ class RedirectAwareProberFactory(ProberFactory):
             # XXX Guilherme Salgado 2007-04-23 bug=109223:
             # We can't assume url to be absolute here.
             self.setURL(url)
-        except UnknownURLScheme as e:
+        except UnknownURLScheme:
             # Since we've got the UnknownURLScheme after a redirect, we need
             # to raise it in a form that can be ignored in the layer above.
             self.failed(UnknownURLSchemeAfterRedirect(url))
diff --git a/lib/lp/registry/tests/test_ociprojectseries.py b/lib/lp/registry/tests/test_ociprojectseries.py
index a8f7ad7..4f51fd1 100644
--- a/lib/lp/registry/tests/test_ociprojectseries.py
+++ b/lib/lp/registry/tests/test_ociprojectseries.py
@@ -132,7 +132,6 @@ class TestOCIProjectSeriesWebservice(TestCaseWithFactory):
 
     def test_get_oci_project_series(self):
         with person_logged_in(self.person):
-            person = removeSecurityProxy(self.person)
             project = removeSecurityProxy(self.factory.makeOCIProject(
                 registrant=self.person))
             series = self.factory.makeOCIProjectSeries(
diff --git a/lib/lp/services/timeout.py b/lib/lp/services/timeout.py
index b8b3a7d..bf462a3 100644
--- a/lib/lp/services/timeout.py
+++ b/lib/lp/services/timeout.py
@@ -225,7 +225,7 @@ class with_timeout:
             t.start()
             try:
                 t.join(timeout)
-            except Exception as e:
+            except Exception:
                 # This will commonly be SoftTimeLimitExceeded from celery,
                 # since celery's timeout often happens before the job's due
                 # to job setup time.
diff --git a/lib/lp/services/twistedsupport/tests/test_gracefulshutdown.py b/lib/lp/services/twistedsupport/tests/test_gracefulshutdown.py
index 27de34e..09581d3 100644
--- a/lib/lp/services/twistedsupport/tests/test_gracefulshutdown.py
+++ b/lib/lp/services/twistedsupport/tests/test_gracefulshutdown.py
@@ -196,7 +196,7 @@ class TestOrderedMultiService(TestCase):
         service2.setServiceParent(oms)
         oms.startService()
         del call_log[:]
-        d = oms.stopService()
+        oms.stopService()
         self.assertEqual(
             [('stopService', 'svc two'), ('stopService', 'svc one')],
             call_log)
diff --git a/lib/lp/snappy/model/snap.py b/lib/lp/snappy/model/snap.py
index ff2fc89..6ec4ac5 100644
--- a/lib/lp/snappy/model/snap.py
+++ b/lib/lp/snappy/model/snap.py
@@ -927,7 +927,7 @@ class Snap(Storm, WebhookTargetMixin):
                         " - %s/%s/%s: Build requested.",
                         self.owner.name, self.name, arch)
                 builds.append(build)
-            except SnapBuildAlreadyPending as e:
+            except SnapBuildAlreadyPending:
                 pass
             except Exception as e:
                 if not allow_failures:
diff --git a/lib/lp/soyuz/scripts/tests/test_initialize_distroseries.py b/lib/lp/soyuz/scripts/tests/test_initialize_distroseries.py
index 7071e6f..e86a857 100644
--- a/lib/lp/soyuz/scripts/tests/test_initialize_distroseries.py
+++ b/lib/lp/soyuz/scripts/tests/test_initialize_distroseries.py
@@ -1090,8 +1090,6 @@ class TestInitializeDistroSeries(InitializationHelperTestCase):
         packages = ('udev', 'chromium', 'libc6')
         for pkg in packages:
             test1.addSources(pkg)
-        packageset1 = getUtility(IPackagesetSet).getByName(
-            self.parent, u'test1')
         child = self._fullInitialize(
             [self.parent], packagesets=[])
         self.assertRaises(
@@ -1118,10 +1116,6 @@ class TestInitializeDistroSeries(InitializationHelperTestCase):
             test1.addSources(pkg)
         for pkg in packages_test2:
             test2.addSources(pkg)
-        packageset1 = getUtility(IPackagesetSet).getByName(
-            self.parent, u'test1')
-        packageset2 = getUtility(IPackagesetSet).getByName(
-            self.parent, u'test2')
         child = self._fullInitialize(
             [self.parent], packagesets=None)
         child_test1 = getUtility(IPackagesetSet).getByName(child, u'test1')
diff --git a/utilities/list-pages b/utilities/list-pages
index 7bce9d8..c1c935f 100755
--- a/utilities/list-pages
+++ b/utilities/list-pages
@@ -114,7 +114,6 @@ def has_page_title(a):
     template = get_template_filename(view)
     if template is None:
         return False
-    name = os.path.splitext(os.path.basename(template))[0].replace('-', '_')
     if (getattr(view, 'page_title', marker) is marker):
         return False
     return has_html_element(template)
diff --git a/utilities/paste b/utilities/paste
index 135b5a1..68290f4 100755
--- a/utilities/paste
+++ b/utilities/paste
@@ -39,7 +39,7 @@ look something like this:
 
 
 def parse_arguments():
-    parser = OptionParser(usage='%prog [options] [title] < stdin')
+    parser = OptionParser(usage='%prog [options] < stdin')
     parser.add_option('-b', '--browser',
                       default=False, action='store_true',
                       help='Open web browser to the pastebin.')
@@ -53,11 +53,7 @@ def parse_arguments():
                       type='string',
                       help='File to pastebin instead of stdin.')
     options, arguments = parser.parse_args()
-    if len(arguments) == 0:
-        parser.title = None
-    elif len(arguments) == 1:
-        parser.title = arguments[0]
-    else:
+    if arguments:
         parser.error('Too many arguments')
         # Does not return
     parser.options = options
@@ -98,11 +94,6 @@ def main():
     except KeyError:
         poster = pwd.getpwuid(os.getuid()).pw_name
 
-    if parser.title is None:
-        title = "The loser %s didn't even add a title" % poster
-    else:
-        title = parser.title
-
     if parser.options.file:
         f = open(parser.options.file)
         try:
diff --git a/utilities/pgbackup.py b/utilities/pgbackup.py
index 51a7f4b..3bf7b35 100755
--- a/utilities/pgbackup.py
+++ b/utilities/pgbackup.py
@@ -53,7 +53,6 @@ def main(options, databases):
             log.fatal("%s already exists." % dest)
             return 1
  
-    exit_code = 0
     for database in databases:
         dest =  os.path.join(backup_dir, '%s.%s.dump' % (database, today))
 
diff --git a/utilities/pgstats.py b/utilities/pgstats.py
index 5e2fe06..30e1ac3 100755
--- a/utilities/pgstats.py
+++ b/utilities/pgstats.py
@@ -114,9 +114,12 @@ def main(dbname):
             dead_tuple_percent = stat['dead_tuple_percent']
             dead_len = stat['dead_tuple_len'] / (1024*1024)
             return (
-                    '%(name)s (%(dead_len)0.2fMB, '
-                    '%(dead_tuple_percent)0.2f%%)' % vars()
-                    )
+                '%(name)s (%(dead_len)0.2fMB, '
+                '%(dead_tuple_percent)0.2f%%)' % {
+                    'name': name,
+                    'dead_len': dead_len,
+                    'dead_tuple_percent': dead_tuple_percent,
+                    })
         if len(stats) > 0:
             print_row('Needing vacuum', statstr(stats[0]))
             for stat in stats[1:]: