Patchwork D6192: cleanup: use set literals where possible

login
register
mail settings
Submitter phabricator
Date April 3, 2019, 8 p.m.
Message ID <differential-rev-PHID-DREV-vchozbvzss6p344pdcxl-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/39464/
State Superseded
Headers show

Comments

phabricator - April 3, 2019, 8 p.m.
martinvonz created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D6192

AFFECTED FILES
  hgext/fastannotate/commands.py
  hgext/largefiles/basestore.py
  hgext/mq.py
  hgext/rebase.py
  hgext/remotefilelog/__init__.py
  hgext/remotefilelog/repack.py
  hgext/show.py
  hgext/uncommit.py
  mercurial/bundle2.py
  mercurial/cmdutil.py
  mercurial/dagop.py
  mercurial/exchange.py
  mercurial/hbisect.py
  mercurial/help.py
  mercurial/merge.py
  mercurial/obsolete.py
  mercurial/revlogutils/deltas.py
  mercurial/wireprotov1server.py

CHANGE DETAILS




To: martinvonz, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/mercurial/wireprotov1server.py b/mercurial/wireprotov1server.py
--- a/mercurial/wireprotov1server.py
+++ b/mercurial/wireprotov1server.py
@@ -345,7 +345,7 @@ 
       one specific branch of many.
     """
     def decodehexstring(s):
-        return set([binascii.unhexlify(h) for h in s.split(';')])
+        return {binascii.unhexlify(h) for h in s.split(';')}
 
     manifest = repo.vfs.tryread('pullbundles.manifest')
     if not manifest:
diff --git a/mercurial/revlogutils/deltas.py b/mercurial/revlogutils/deltas.py
--- a/mercurial/revlogutils/deltas.py
+++ b/mercurial/revlogutils/deltas.py
@@ -637,7 +637,7 @@ 
 
     deltas_limit = textlen * LIMIT_DELTA2TEXT
 
-    tested = set([nullrev])
+    tested = {nullrev}
     candidates = _refinedgroups(revlog, p1, p2, cachedelta)
     while True:
         temptative = candidates.send(good)
diff --git a/mercurial/obsolete.py b/mercurial/obsolete.py
--- a/mercurial/obsolete.py
+++ b/mercurial/obsolete.py
@@ -743,7 +743,7 @@ 
                 pruned = [m for m in succsmarkers.get(current, ()) if not m[1]]
                 direct.update(pruned)
             direct -= seenmarkers
-            pendingnodes = set([m[0] for m in direct])
+            pendingnodes = {m[0] for m in direct}
             seenmarkers |= direct
             pendingnodes -= seennodes
             seennodes |= pendingnodes
diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -815,8 +815,8 @@ 
                     fileconflicts.add(f)
 
         allconflicts = fileconflicts | pathconflicts
-        ignoredconflicts = set([c for c in allconflicts
-                                if repo.dirstate._ignore(c)])
+        ignoredconflicts = {c for c in allconflicts
+                            if repo.dirstate._ignore(c)}
         unknownconflicts = allconflicts - ignoredconflicts
         collectconflicts(ignoredconflicts, ignoredconfig)
         collectconflicts(unknownconflicts, unknownconfig)
@@ -1104,7 +1104,7 @@ 
     Raise an exception if the merge cannot be completed because the repo is
     narrowed.
     """
-    nooptypes = set(['k']) # TODO: handle with nonconflicttypes
+    nooptypes = {'k'} # TODO: handle with nonconflicttypes
     nonconflicttypes = set('a am c cm f g r e'.split())
     # We mutate the items in the dict during iteration, so iterate
     # over a copy.
diff --git a/mercurial/help.py b/mercurial/help.py
--- a/mercurial/help.py
+++ b/mercurial/help.py
@@ -748,7 +748,7 @@ 
                 ct = mod.cmdtable
             except AttributeError:
                 ct = {}
-            modcmds = set([c.partition('|')[0] for c in ct])
+            modcmds = {c.partition('|')[0] for c in ct}
             rst.extend(helplist(modcmds.__contains__))
         else:
             rst.append(_("(use 'hg help extensions' for information on enabling"
diff --git a/mercurial/hbisect.py b/mercurial/hbisect.py
--- a/mercurial/hbisect.py
+++ b/mercurial/hbisect.py
@@ -34,7 +34,7 @@ 
 
     changelog = repo.changelog
     clparents = changelog.parentrevs
-    skip = set([changelog.rev(n) for n in state['skip']])
+    skip = {changelog.rev(n) for n in state['skip']}
 
     def buildancestors(bad, good):
         badrev = min([changelog.rev(n) for n in bad])
diff --git a/mercurial/exchange.py b/mercurial/exchange.py
--- a/mercurial/exchange.py
+++ b/mercurial/exchange.py
@@ -707,8 +707,8 @@ 
 
     remotebookmark = listkeys(remote, 'bookmarks')
 
-    explicit = set([repo._bookmarks.expandname(bookmark)
-                    for bookmark in pushop.bookmarks])
+    explicit = {repo._bookmarks.expandname(bookmark)
+                for bookmark in pushop.bookmarks}
 
     remotebookmark = bookmod.unhexlifybookmarks(remotebookmark)
     comp = bookmod.comparebookmarks(repo, repo._bookmarks, remotebookmark)
diff --git a/mercurial/dagop.py b/mercurial/dagop.py
--- a/mercurial/dagop.py
+++ b/mercurial/dagop.py
@@ -764,7 +764,7 @@ 
     the input set.
     """
     headrevs = set(revs)
-    parents = set([node.nullrev])
+    parents = {node.nullrev}
     up = parents.update
 
     for rev in revs:
diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -458,7 +458,7 @@ 
 
     def __init__(self, dirpath):
         self.path = dirpath
-        self.statuses = set([])
+        self.statuses = set()
         self.files = []
         self.subdirs = {}
 
@@ -2495,8 +2495,7 @@ 
         if len(old.parents()) > 1:
             # ctx.files() isn't reliable for merges, so fall back to the
             # slower repo.status() method
-            files = set([fn for st in base.status(old)[:3]
-                         for fn in st])
+            files = {fn for st in base.status(old)[:3] for fn in st}
         else:
             files = set(old.files())
 
diff --git a/mercurial/bundle2.py b/mercurial/bundle2.py
--- a/mercurial/bundle2.py
+++ b/mercurial/bundle2.py
@@ -2315,7 +2315,7 @@ 
                                         oldmatcher=oldmatcher,
                                         matcher=newmatcher,
                                         fullnodes=commonnodes)
-        cgdata = packer.generate(set([nodemod.nullid]), list(commonnodes),
+        cgdata = packer.generate({nodemod.nullid}, list(commonnodes),
                                  False, 'narrow_widen', changelog=False)
 
         part = bundler.newpart('changegroup', data=cgdata)
diff --git a/hgext/uncommit.py b/hgext/uncommit.py
--- a/hgext/uncommit.py
+++ b/hgext/uncommit.py
@@ -147,7 +147,7 @@ 
             # if not everything tracked in that directory can be
             # uncommitted.
             if badfiles:
-                badfiles -= set([f for f in util.dirs(eligible)])
+                badfiles -= {f for f in util.dirs(eligible)}
 
             for f in sorted(badfiles):
                 if f in s.clean:
diff --git a/hgext/show.py b/hgext/show.py
--- a/hgext/show.py
+++ b/hgext/show.py
@@ -243,7 +243,7 @@ 
     else:
         newheads = set()
 
-    allrevs = set(stackrevs) | newheads | set([baserev])
+    allrevs = set(stackrevs) | newheads | {baserev}
     nodelen = longestshortest(repo, allrevs)
 
     try:
diff --git a/hgext/remotefilelog/repack.py b/hgext/remotefilelog/repack.py
--- a/hgext/remotefilelog/repack.py
+++ b/hgext/remotefilelog/repack.py
@@ -154,9 +154,9 @@ 
 
     # Either an oversize index or datapack will trigger cleanup of the whole
     # pack:
-    oversized = set([os.path.splitext(path)[0] for path, ftype, stat in files
+    oversized = {os.path.splitext(path)[0] for path, ftype, stat in files
         if (stat.st_size > maxsize and (os.path.splitext(path)[1]
-                                        in VALIDEXTS))])
+                                        in VALIDEXTS))}
 
     for rootfname in oversized:
         rootpath = os.path.join(folder, rootfname)
diff --git a/hgext/remotefilelog/__init__.py b/hgext/remotefilelog/__init__.py
--- a/hgext/remotefilelog/__init__.py
+++ b/hgext/remotefilelog/__init__.py
@@ -804,7 +804,7 @@ 
         return
 
     reposfile = open(repospath, 'rb')
-    repos = set([r[:-1] for r in reposfile.readlines()])
+    repos = {r[:-1] for r in reposfile.readlines()}
     reposfile.close()
 
     # build list of useful files
diff --git a/hgext/rebase.py b/hgext/rebase.py
--- a/hgext/rebase.py
+++ b/hgext/rebase.py
@@ -1878,8 +1878,8 @@ 
     obsolete successors.
     """
     obsoletenotrebased = {}
-    obsoletewithoutsuccessorindestination = set([])
-    obsoleteextinctsuccessors = set([])
+    obsoletewithoutsuccessorindestination = set()
+    obsoleteextinctsuccessors = set()
 
     assert repo.filtername is None
     cl = repo.changelog
diff --git a/hgext/mq.py b/hgext/mq.py
--- a/hgext/mq.py
+++ b/hgext/mq.py
@@ -1940,7 +1940,7 @@ 
                 self.ui.write(patchname, label='qseries.' + state)
             self.ui.write('\n')
 
-        applied = set([p.name for p in self.applied])
+        applied = {p.name for p in self.applied}
         if length is None:
             length = len(self.series) - start
         if not missing:
@@ -3658,7 +3658,7 @@ 
     """Changesets managed by MQ.
     """
     revsetlang.getargs(x, 0, 0, _("mq takes no arguments"))
-    applied = set([repo[r.node].rev() for r in repo.mq.applied])
+    applied = {repo[r.node].rev() for r in repo.mq.applied}
     return smartset.baseset([r for r in subset if r in applied])
 
 # tell hggettext to extract docstrings from these functions:
diff --git a/hgext/largefiles/basestore.py b/hgext/largefiles/basestore.py
--- a/hgext/largefiles/basestore.py
+++ b/hgext/largefiles/basestore.py
@@ -136,7 +136,7 @@ 
         failed = self._verifyfiles(contents, filestocheck)
 
         numrevs = len(verified)
-        numlfiles = len(set([fname for (fname, fnode) in verified]))
+        numlfiles = len({fname for (fname, fnode) in verified})
         if contents:
             self.ui.status(
                 _('verified contents of %d revisions of %d largefiles\n')
diff --git a/hgext/fastannotate/commands.py b/hgext/fastannotate/commands.py
--- a/hgext/fastannotate/commands.py
+++ b/hgext/fastannotate/commands.py
@@ -198,9 +198,9 @@ 
         formatter.write(result, lines, existinglines=existinglines)
     formatter.end()
 
-_newopts = set([])
-_knownopts = set([opt[1].replace('-', '_') for opt in
-                  (fastannotatecommandargs[r'options'] + commands.globalopts)])
+_newopts = set()
+_knownopts = {opt[1].replace('-', '_') for opt in
+              (fastannotatecommandargs[r'options'] + commands.globalopts)}
 
 def _annotatewrapper(orig, ui, repo, *pats, **opts):
     """used by wrapdefault"""