diff --git a/hgext/convert/bzr.py b/hgext/convert/bzr.py
--- a/hgext/convert/bzr.py
+++ b/hgext/convert/bzr.py
@@ -61,7 +61,7 @@ class bzr_source(converter_source):
             try:
                 tree = dir.open_workingtree(recommend_upgrade=False)
                 branch = tree.branch
-            except (errors.NoWorkingTree, errors.NotLocalUrl), e:
+            except (errors.NoWorkingTree, errors.NotLocalUrl):
                 tree = None
                 branch = dir.open_branch()
             if (tree is not None and tree.bzrdir.root_transport.base !=
diff --git a/hgext/convert/cvs.py b/hgext/convert/cvs.py
--- a/hgext/convert/cvs.py
+++ b/hgext/convert/cvs.py
@@ -53,8 +53,6 @@ class convert_cvs(converter_source):
         try:
             os.chdir(self.path)
             id = None
-            state = 0
-            filerevids = {}
 
             cache = 'update'
             if not self.ui.configbool('convert', 'cvsps.cache', True):
diff --git a/hgext/inotify/client.py b/hgext/inotify/client.py
--- a/hgext/inotify/client.py
+++ b/hgext/inotify/client.py
@@ -21,7 +21,6 @@ def start_server(function):
     Raise QueryFailed if something went wrong
     """
     def decorated_function(self, *args):
-        result = None
         try:
             return function(self, *args)
         except (OSError, socket.error), err:
diff --git a/hgext/mq.py b/hgext/mq.py
--- a/hgext/mq.py
+++ b/hgext/mq.py
@@ -1756,7 +1756,6 @@ def applied(ui, repo, patch=None, **opts
     """print the patches already applied"""
 
     q = repo.mq
-    l = len(q.applied)
 
     if patch:
         if patch not in q.series:
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -1360,7 +1360,7 @@ def debuginstall(ui):
     # check username
     ui.status(_("Checking username...\n"))
     try:
-        user = ui.username()
+        ui.username()
     except util.Abort, e:
         ui.write(" %s\n" % e)
         ui.write(_(" (specify a username in your .hgrc file)\n"))
diff --git a/mercurial/hgweb/webcommands.py b/mercurial/hgweb/webcommands.py
--- a/mercurial/hgweb/webcommands.py
+++ b/mercurial/hgweb/webcommands.py
@@ -383,7 +383,6 @@ def tags(web, req, tmpl):
                 latestentry=lambda **x: entries(True, 1, **x))
 
 def branches(web, req, tmpl):
-    b = web.repo.branchtags()
     tips = (web.repo[n] for t, n in web.repo.branchtags().iteritems())
     heads = web.repo.heads()
     parity = paritygen(web.stripecount)
diff --git a/mercurial/windows.py b/mercurial/windows.py
--- a/mercurial/windows.py
+++ b/mercurial/windows.py
@@ -288,7 +288,7 @@ def rename(src, dst):
     '''atomically rename file src to dst, replacing dst if it exists'''
     try:
         os.rename(src, dst)
-    except OSError, err: # FIXME: check err (EEXIST ?)
+    except OSError: # FIXME: check err (EEXIST ?)
 
         # On windows, rename to existing file is not allowed, so we
         # must delete destination first. But if a file is open, unlink
diff --git a/mercurial/wireproto.py b/mercurial/wireproto.py
--- a/mercurial/wireproto.py
+++ b/mercurial/wireproto.py
@@ -123,7 +123,7 @@ class wirerepository(repo.repository):
                 _('push failed:'), output)
         try:
             ret = int(ret)
-        except ValueError, err:
+        except ValueError:
             raise error.ResponseError(
                 _('push failed (unexpected response):'), ret)