[PATCH] cleanup: use set literals

Augie Fackler raf at durin42.com
Mon May 15 13:45:46 EDT 2017


On Mon, May 15, 2017 at 09:33:16AM -0700, Martin von Zweigbergk via Mercurial-devel wrote:
> # HG changeset patch
> # User Martin von Zweigbergk <martinvonz at google.com>
> # Date 1486774589 28800
> #      Fri Feb 10 16:56:29 2017 -0800
> # Node ID 4c861a7d3a2fc1a18bafdcf931a4aade46398c2b
> # Parent  539cbe0f8fa38b771b9056d8e7ed51e999073f02
> cleanup: use set literals

+1, but I'll leave this for Sean or Greg to take so we can verify that
things are working correctly.

>
> We no longer support Python 2.6, so we can now use set literals.
>
> diff --git a/contrib/import-checker.py b/contrib/import-checker.py
> --- a/contrib/import-checker.py
> +++ b/contrib/import-checker.py
> @@ -213,7 +213,7 @@
>          yield m
>      for m in ['cffi']:
>          yield m
> -    stdlib_prefixes = set([sys.prefix, sys.exec_prefix])
> +    stdlib_prefixes = {sys.prefix, sys.exec_prefix}
>      # We need to supplement the list of prefixes for the search to work
>      # when run from within a virtualenv.
>      for mod in (BaseHTTPServer, zlib):
> diff --git a/contrib/synthrepo.py b/contrib/synthrepo.py
> --- a/contrib/synthrepo.py
> +++ b/contrib/synthrepo.py
> @@ -71,7 +71,7 @@
>  cmdtable = {}
>  command = cmdutil.command(cmdtable)
>
> -newfile = set(('new fi', 'rename', 'copy f', 'copy t'))
> +newfile = {'new fi', 'rename', 'copy f', 'copy t'}
>
>  def zerodict():
>      return collections.defaultdict(lambda: 0)
> @@ -336,7 +336,7 @@
>      wlock = repo.wlock()
>      lock = repo.lock()
>
> -    nevertouch = set(('.hgsub', '.hgignore', '.hgtags'))
> +    nevertouch = {'.hgsub', '.hgignore', '.hgtags'}
>
>      progress = ui.progress
>      _synthesizing = _('synthesizing')
> diff --git a/hgext/convert/filemap.py b/hgext/convert/filemap.py
> --- a/hgext/convert/filemap.py
> +++ b/hgext/convert/filemap.py
> @@ -310,7 +310,7 @@
>              # map to any revision in the restricted graph.  Put SKIPREV
>              # in the set of wanted ancestors to simplify code elsewhere
>              self.parentmap[rev] = SKIPREV
> -            self.wantedancestors[rev] = set((SKIPREV,))
> +            self.wantedancestors[rev] = {SKIPREV}
>              return
>
>          # Reuse the data from our parent.
> diff --git a/hgext/convert/git.py b/hgext/convert/git.py
> --- a/hgext/convert/git.py
> +++ b/hgext/convert/git.py
> @@ -32,7 +32,7 @@
>          return "%s %s" % (self.node, self.path)
>
>  # Keys in extra fields that should not be copied if the user requests.
> -bannedextrakeys = set([
> +bannedextrakeys = {
>      # Git commit object built-ins.
>      'tree',
>      'parent',
> @@ -41,7 +41,7 @@
>      # Mercurial built-ins.
>      'branch',
>      'close',
> -])
> +}
>
>  class convert_git(common.converter_source, common.commandline):
>      # Windows does not support GIT_DIR= construct while other systems
> @@ -455,9 +455,9 @@
>              ('refs/heads/', '')
>          ]
>
> -        exclude = set([
> +        exclude = {
>              'refs/remotes/origin/HEAD',
> -        ])
> +        }
>
>          try:
>              output, status = self.gitrunlines('show-ref')
> diff --git a/hgext/histedit.py b/hgext/histedit.py
> --- a/hgext/histedit.py
> +++ b/hgext/histedit.py
> @@ -1641,8 +1641,8 @@
>      if os.path.exists(os.path.join(repo.path, 'histedit-state')):
>          state = histeditstate(repo)
>          state.read()
> -        histedit_nodes = set([action.node for action
> -                             in state.actions if action.node])
> +        histedit_nodes = {action.node for action
> +                          in state.actions if action.node}
>          common_nodes = histedit_nodes & set(nodelist)
>          if common_nodes:
>              raise error.Abort(_("histedit in progress, can't strip %s")
> diff --git a/hgext/journal.py b/hgext/journal.py
> --- a/hgext/journal.py
> +++ b/hgext/journal.py
> @@ -158,7 +158,7 @@
>              util.safehasattr(repo, 'journal')):
>          sharedrepo = share._getsrcrepo(repo)
>          sharedfeatures = _readsharedfeatures(repo)
> -        if sharedrepo and sharedfeatures > set(['journal']):
> +        if sharedrepo and sharedfeatures > {'journal'}:
>              # there is a shared repository and there are shared journal entries
>              # to copy. move shared date over from source to destination but
>              # move the local file first
> diff --git a/hgext/largefiles/__init__.py b/hgext/largefiles/__init__.py
> --- a/hgext/largefiles/__init__.py
> +++ b/hgext/largefiles/__init__.py
> @@ -129,7 +129,7 @@
>
>  def featuresetup(ui, supported):
>      # don't die on seeing a repo with the largefiles requirement
> -    supported |= set(['largefiles'])
> +    supported |= {'largefiles'}
>
>  def uisetup(ui):
>      localrepo.localrepository.featuresetupfuncs.add(featuresetup)
> diff --git a/hgext/rebase.py b/hgext/rebase.py
> --- a/hgext/rebase.py
> +++ b/hgext/rebase.py
> @@ -242,7 +242,7 @@
>          skipped = set()
>          # recompute the set of skipped revs
>          if not collapse:
> -            seen = set([dest])
> +            seen = {dest}
>              for old, new in sorted(state.items()):
>                  if new != revtodo and new in seen:
>                      skipped.add(old)
> @@ -250,7 +250,7 @@
>          repo.ui.debug('computed skipped revs: %s\n' %
>                          (' '.join(str(r) for r in sorted(skipped)) or None))
>          repo.ui.debug('rebase status resumed\n')
> -        _setrebasesetvisibility(repo, set(state.keys()) | set([originalwd]))
> +        _setrebasesetvisibility(repo, set(state.keys()) | {originalwd})
>
>          self.originalwd = originalwd
>          self.dest = dest
> @@ -1235,7 +1235,7 @@
>      rebaseset: set of rev
>      '''
>      originalwd = repo['.'].rev()
> -    _setrebasesetvisibility(repo, set(rebaseset) | set([originalwd]))
> +    _setrebasesetvisibility(repo, set(rebaseset) | {originalwd})
>
>      # This check isn't strictly necessary, since mq detects commits over an
>      # applied patch. But it prevents messing up the working directory when
> diff --git a/hgext/shelve.py b/hgext/shelve.py
> --- a/hgext/shelve.py
> +++ b/hgext/shelve.py
> @@ -352,7 +352,7 @@
>      """return all mutable ancestors for ctx (included)
>
>      Much faster than the revset ancestors(ctx) & draft()"""
> -    seen = set([nodemod.nullrev])
> +    seen = {nodemod.nullrev}
>      visit = collections.deque()
>      visit.append(ctx)
>      while visit:
> @@ -1006,17 +1006,17 @@
>      all shelved changes, use ``--cleanup``.
>      '''
>      allowables = [
> -        ('addremove', set(['create'])), # 'create' is pseudo action
> -        ('unknown', set(['create'])),
> -        ('cleanup', set(['cleanup'])),
> -#       ('date', set(['create'])), # ignored for passing '--date "0 0"' in tests
> -        ('delete', set(['delete'])),
> -        ('edit', set(['create'])),
> -        ('list', set(['list'])),
> -        ('message', set(['create'])),
> -        ('name', set(['create'])),
> -        ('patch', set(['patch', 'list'])),
> -        ('stat', set(['stat', 'list'])),
> +        ('addremove', {'create'}), # 'create' is pseudo action
> +        ('unknown', {'create'}),
> +        ('cleanup', {'cleanup'}),
> +#       ('date', {'create'}), # ignored for passing '--date "0 0"' in tests
> +        ('delete', {'delete'}),
> +        ('edit', {'create'}),
> +        ('list', {'list'}),
> +        ('message', {'create'}),
> +        ('name', {'create'}),
> +        ('patch', {'patch', 'list'}),
> +        ('stat', {'stat', 'list'}),
>      ]
>      def checkopt(opt):
>          if opts.get(opt):
> diff --git a/hgext/show.py b/hgext/show.py
> --- a/hgext/show.py
> +++ b/hgext/show.py
> @@ -185,7 +185,7 @@
>      # Add working directory parent.
>      wdirrev = repo['.'].rev()
>      if wdirrev != nullrev:
> -        relevant += revset.baseset(set([wdirrev]))
> +        relevant += revset.baseset({wdirrev})
>
>      return subset & relevant
>
> diff --git a/mercurial/__init__.py b/mercurial/__init__.py
> --- a/mercurial/__init__.py
> +++ b/mercurial/__init__.py
> @@ -22,14 +22,14 @@
>
>  # Modules that have both Python and C implementations. See also the
>  # set of .py files under mercurial/pure/.
> -_dualmodules = set([
> +_dualmodules = {
>      'mercurial.base85',
>      'mercurial.bdiff',
>      'mercurial.diffhelpers',
>      'mercurial.mpatch',
>      'mercurial.osutil',
>      'mercurial.parsers',
> -])
> +}
>
>  class hgimporter(object):
>      """Object that conforms to import hook interface defined in PEP-302."""
> diff --git a/mercurial/ancestor.py b/mercurial/ancestor.py
> --- a/mercurial/ancestor.py
> +++ b/mercurial/ancestor.py
> @@ -47,7 +47,7 @@
>                  sv |= poison
>                  if v in nodes:
>                      # history is linear
> -                    return set([v])
> +                    return {v}
>          if sv < poison:
>              for p in pfunc(v):
>                  sp = seen[p]
> @@ -151,7 +151,7 @@
>
>      def hasbases(self):
>          '''whether the common set has any non-trivial bases'''
> -        return self.bases and self.bases != set([nullrev])
> +        return self.bases and self.bases != {nullrev}
>
>      def addbases(self, newbases):
>          '''grow the ancestor set by adding new bases'''
> diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
> --- a/mercurial/cmdutil.py
> +++ b/mercurial/cmdutil.py
> @@ -1692,7 +1692,7 @@
>              last = filelog.rev(node)
>
>          # keep track of all ancestors of the file
> -        ancestors = set([filelog.linkrev(last)])
> +        ancestors = {filelog.linkrev(last)}
>
>          # iterate from latest to oldest revision
>          for rev, flparentlinkrevs, copied in filerevgen(filelog, last):
> diff --git a/mercurial/color.py b/mercurial/color.py
> --- a/mercurial/color.py
> +++ b/mercurial/color.py
> @@ -442,10 +442,10 @@
>          'inverse': _COMMON_LVB_REVERSE_VIDEO, # double-byte charsets only
>      }
>
> -    passthrough = set([_FOREGROUND_INTENSITY,
> -                       _BACKGROUND_INTENSITY,
> -                       _COMMON_LVB_UNDERSCORE,
> -                       _COMMON_LVB_REVERSE_VIDEO])
> +    passthrough = {_FOREGROUND_INTENSITY,
> +                   _BACKGROUND_INTENSITY,
> +                   _COMMON_LVB_UNDERSCORE,
> +                   _COMMON_LVB_REVERSE_VIDEO}
>
>      stdout = _kernel32.GetStdHandle(
>                    _STD_OUTPUT_HANDLE)  # don't close the handle returned
> diff --git a/mercurial/copies.py b/mercurial/copies.py
> --- a/mercurial/copies.py
> +++ b/mercurial/copies.py
> @@ -637,7 +637,7 @@
>          return
>
>      of = None
> -    seen = set([f])
> +    seen = {f}
>      for oc in getfctx(f, m1[f]).ancestors():
>          ocr = oc.linkrev()
>          of = oc.path()
> diff --git a/mercurial/discovery.py b/mercurial/discovery.py
> --- a/mercurial/discovery.py
> +++ b/mercurial/discovery.py
> @@ -254,7 +254,7 @@
>      newheads = list(c.node() for c in r)
>      # set some unsynced head to issue the "unsynced changes" warning
>      if inc:
> -        unsynced = set([None])
> +        unsynced = {None}
>      else:
>          unsynced = set()
>      return {None: (oldheads, newheads, unsynced)}
> diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
> --- a/mercurial/dispatch.py
> +++ b/mercurial/dispatch.py
> @@ -749,7 +749,7 @@
>      # imported and commands.table is populated.
>      debugcommands.command
>
> -    uis = set([ui, lui])
> +    uis = {ui, lui}
>
>      if req.repo:
>          uis.add(req.repo.ui)
> diff --git a/mercurial/encoding.py b/mercurial/encoding.py
> --- a/mercurial/encoding.py
> +++ b/mercurial/encoding.py
> @@ -30,9 +30,9 @@
>             "206a 206b 206c 206d 206e 206f feff".split()]
>  # verify the next function will work
>  if pycompat.ispy3:
> -    assert set(i[0] for i in _ignore) == set([ord(b'\xe2'), ord(b'\xef')])
> +    assert set(i[0] for i in _ignore) == {ord(b'\xe2'), ord(b'\xef')}
>  else:
> -    assert set(i[0] for i in _ignore) == set(["\xe2", "\xef"])
> +    assert set(i[0] for i in _ignore) == {"\xe2", "\xef"}
>
>  def hfsignoreclean(s):
>      """Remove codepoints ignored by HFS+ from s.
> diff --git a/mercurial/exchange.py b/mercurial/exchange.py
> --- a/mercurial/exchange.py
> +++ b/mercurial/exchange.py
> @@ -43,7 +43,7 @@
>                          }
>
>  # Compression engines allowed in version 1. THIS SHOULD NEVER CHANGE.
> -_bundlespecv1compengines = set(['gzip', 'bzip2', 'none'])
> +_bundlespecv1compengines = {'gzip', 'bzip2', 'none'}
>
>  def parsebundlespec(repo, spec, strict=True, externalnames=False):
>      """Parse a bundle string specification into parts.
> @@ -1519,7 +1519,7 @@
>
>  def caps20to10(repo):
>      """return a set with appropriate options to use bundle20 during getbundle"""
> -    caps = set(['HG20'])
> +    caps = {'HG20'}
>      capsblob = bundle2.encodecaps(bundle2.getrepocaps(repo))
>      caps.add('bundle2=' + urlreq.quote(capsblob))
>      return caps
> diff --git a/mercurial/extensions.py b/mercurial/extensions.py
> --- a/mercurial/extensions.py
> +++ b/mercurial/extensions.py
> @@ -28,8 +28,8 @@
>  _disabledextensions = {}
>  _aftercallbacks = {}
>  _order = []
> -_builtin = set(['hbisect', 'bookmarks', 'parentrevspec', 'progress', 'interhg',
> -                'inotify', 'hgcia'])
> +_builtin = {'hbisect', 'bookmarks', 'parentrevspec', 'progress', 'interhg',
> +            'inotify', 'hgcia'}
>
>  def extensions(ui=None):
>      if ui:
> diff --git a/mercurial/fancyopts.py b/mercurial/fancyopts.py
> --- a/mercurial/fancyopts.py
> +++ b/mercurial/fancyopts.py
> @@ -14,7 +14,7 @@
>  )
>
>  # Set of flags to not apply boolean negation logic on
> -nevernegate = set([
> +nevernegate = {
>      # avoid --no-noninteractive
>      'noninteractive',
>      # These two flags are special because they cause hg to do one
> @@ -22,7 +22,7 @@
>      # like aliases anyway.
>      'help',
>      'version',
> -    ])
> +}
>
>  def gnugetopt(args, options, longoptions):
>      """Parse options mostly like getopt.gnu_getopt.
> diff --git a/mercurial/fileset.py b/mercurial/fileset.py
> --- a/mercurial/fileset.py
> +++ b/mercurial/fileset.py
> @@ -37,7 +37,7 @@
>      "end": (0, None, None, None, None),
>  }
>
> -keywords = set(['and', 'or', 'not'])
> +keywords = {'and', 'or', 'not'}
>
>  globchars = ".*{}[]?/\\_"
>
> diff --git a/mercurial/help.py b/mercurial/help.py
> --- a/mercurial/help.py
> +++ b/mercurial/help.py
> @@ -34,7 +34,7 @@
>      webcommands,
>  )
>
> -_exclkeywords = set([
> +_exclkeywords = {
>      "(ADVANCED)",
>      "(DEPRECATED)",
>      "(EXPERIMENTAL)",
> @@ -44,7 +44,7 @@
>      _("(DEPRECATED)"),
>      # i18n: "(EXPERIMENTAL)" is a keyword, must be translated consistently
>      _("(EXPERIMENTAL)"),
> -    ])
> +}
>
>  def listexts(header, exts, indent=1, showdeprecated=False):
>      '''return a text listing of the given extensions'''
> diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
> --- a/mercurial/localrepo.py
> +++ b/mercurial/localrepo.py
> @@ -113,9 +113,9 @@
>          return orig(repo.unfiltered(), *args, **kwargs)
>      return wrapper
>
> -moderncaps = set(('lookup', 'branchmap', 'pushkey', 'known', 'getbundle',
> -                  'unbundle'))
> -legacycaps = moderncaps.union(set(['changegroupsubset']))
> +moderncaps = {'lookup', 'branchmap', 'pushkey', 'known', 'getbundle',
> +              'unbundle'}
> +legacycaps = moderncaps.union({'changegroupsubset'})
>
>  class localpeer(peer.peerrepository):
>      '''peer for a local repo; reflects only the most recent API'''
> @@ -247,11 +247,11 @@
>
>  class localrepository(object):
>
> -    supportedformats = set(('revlogv1', 'generaldelta', 'treemanifest',
> -                            'manifestv2'))
> -    _basesupported = supportedformats | set(('store', 'fncache', 'shared',
> -                                             'relshared', 'dotencode'))
> -    openerreqs = set(('revlogv1', 'generaldelta', 'treemanifest', 'manifestv2'))
> +    supportedformats = {'revlogv1', 'generaldelta', 'treemanifest',
> +                        'manifestv2'}
> +    _basesupported = supportedformats | {'store', 'fncache', 'shared',
> +                                         'relshared', 'dotencode'}
> +    openerreqs = {'revlogv1', 'generaldelta', 'treemanifest', 'manifestv2'}
>      filtername = None
>
>      # a list of (ui, featureset) functions.
> @@ -2020,7 +2020,7 @@
>      new repositories.
>      """
>      ui = repo.ui
> -    requirements = set(['revlogv1'])
> +    requirements = {'revlogv1'}
>      if ui.configbool('format', 'usestore', True):
>          requirements.add('store')
>          if ui.configbool('format', 'usefncache', True):
> diff --git a/mercurial/match.py b/mercurial/match.py
> --- a/mercurial/match.py
> +++ b/mercurial/match.py
> @@ -236,7 +236,7 @@
>
>      @propertycache
>      def _dirs(self):
> -        return set(util.dirs(self._fileroots)) | set(['.'])
> +        return set(util.dirs(self._fileroots)) | {'.'}
>
>      def visitdir(self, dir):
>          '''Decides whether a directory should be visited based on whether it
> diff --git a/mercurial/namespaces.py b/mercurial/namespaces.py
> --- a/mercurial/namespaces.py
> +++ b/mercurial/namespaces.py
> @@ -46,7 +46,7 @@
>                        logfmt=_("tag:         %s\n"),
>                        listnames=tagnames,
>                        namemap=tagnamemap, nodemap=tagnodemap,
> -                      deprecated=set(['tip']))
> +                      deprecated={'tip'})
>          self.addnamespace(n)
>
>          bnames = lambda repo: repo.branchmap().keys()
> diff --git a/mercurial/node.py b/mercurial/node.py
> --- a/mercurial/node.py
> +++ b/mercurial/node.py
> @@ -23,7 +23,7 @@
>  addednodeid = ('0' * 15) + 'added'
>  modifiednodeid = ('0' * 12) + 'modified'
>
> -wdirnodes = set((newnodeid, addednodeid, modifiednodeid))
> +wdirnodes = {newnodeid, addednodeid, modifiednodeid}
>
>  # pseudo identifiers for working directory
>  # (they are experimental, so don't add too many dependencies on them)
> diff --git a/mercurial/posix.py b/mercurial/posix.py
> --- a/mercurial/posix.py
> +++ b/mercurial/posix.py
> @@ -474,7 +474,7 @@
>  def setsignalhandler():
>      pass
>
> -_wantedkinds = set([stat.S_IFREG, stat.S_IFLNK])
> +_wantedkinds = {stat.S_IFREG, stat.S_IFLNK}
>
>  def statfiles(files):
>      '''Stat each file in files. Yield each stat, or None if a file does not
> diff --git a/mercurial/revlog.py b/mercurial/revlog.py
> --- a/mercurial/revlog.py
> +++ b/mercurial/revlog.py
> @@ -913,8 +913,8 @@
>              stop = []
>          stoprevs = set([self.rev(n) for n in stop])
>          startrev = self.rev(start)
> -        reachable = set((startrev,))
> -        heads = set((startrev,))
> +        reachable = {startrev}
> +        heads = {startrev}
>
>          parentrevs = self.parentrevs
>          for r in self.revs(start=startrev + 1):
> @@ -2039,7 +2039,7 @@
>      DELTAREUSESAMEREVS = 'samerevs'
>      DELTAREUSENEVER = 'never'
>
> -    DELTAREUSEALL = set(['always', 'samerevs', 'never'])
> +    DELTAREUSEALL = {'always', 'samerevs', 'never'}
>
>      def clone(self, tr, destrevlog, addrevisioncb=None,
>                deltareuse=DELTAREUSESAMEREVS, aggressivemergedeltas=None):
> diff --git a/mercurial/revset.py b/mercurial/revset.py
> --- a/mercurial/revset.py
> +++ b/mercurial/revset.py
> @@ -451,9 +451,8 @@
>              for bmrev in matchrevs:
>                  bms.add(repo[bmrev].rev())
>      else:
> -        bms = set([repo[r].rev()
> -                   for r in repo._bookmarks.values()])
> -    bms -= set([node.nullrev])
> +        bms = {repo[r].rev() for r in repo._bookmarks.values()}
> +    bms -= {node.nullrev}
>      return subset & bms
>
>  @predicate('branch(string or set)', safe=True)
> @@ -1276,7 +1275,7 @@
>              if name not in ns.deprecated:
>                  names.update(repo[n].rev() for n in ns.nodes(repo, name))
>
> -    names -= set([node.nullrev])
> +    names -= {node.nullrev}
>      return subset & names
>
>  @predicate('id(string)', safe=True)
> @@ -1363,8 +1362,8 @@
>                  return src
>              src = prev
>
> -    o = set([_firstsrc(r) for r in dests])
> -    o -= set([None])
> +    o = {_firstsrc(r) for r in dests}
> +    o -= {None}
>      # XXX we should turn this into a baseset instead of a set, smartset may do
>      # some optimizations from the fact this is a baseset.
>      return subset & o
> @@ -1393,7 +1392,7 @@
>      outgoing = discovery.findcommonoutgoing(repo, other, onlyheads=revs)
>      repo.ui.popbuffer()
>      cl = repo.changelog
> -    o = set([cl.rev(r) for r in outgoing.missing])
> +    o = {cl.rev(r) for r in outgoing.missing}
>      return subset & o
>
>  @predicate('p1([set])', safe=True)
> @@ -1410,7 +1409,7 @@
>      cl = repo.changelog
>      for r in getset(repo, fullreposet(repo), x):
>          ps.add(cl.parentrevs(r)[0])
> -    ps -= set([node.nullrev])
> +    ps -= {node.nullrev}
>      # XXX we should turn this into a baseset instead of a set, smartset may do
>      # some optimizations from the fact this is a baseset.
>      return subset & ps
> @@ -1433,7 +1432,7 @@
>      cl = repo.changelog
>      for r in getset(repo, fullreposet(repo), x):
>          ps.add(cl.parentrevs(r)[1])
> -    ps -= set([node.nullrev])
> +    ps -= {node.nullrev}
>      # XXX we should turn this into a baseset instead of a set, smartset may do
>      # some optimizations from the fact this is a baseset.
>      return subset & ps
> @@ -1458,7 +1457,7 @@
>                  up(p.rev() for p in repo[r].parents())
>              else:
>                  up(parentrevs(r))
> -    ps -= set([node.nullrev])
> +    ps -= {node.nullrev}
>      return subset & ps
>
>  def _phase(repo, subset, *targets):
> @@ -1965,7 +1964,7 @@
>              else:
>                  # This is a new head. We create a new subgroup for it.
>                  targetidx = len(groups)
> -                groups.append(([], set([rev])))
> +                groups.append(([], {rev}))
>
>              gr = groups[targetidx]
>
> @@ -2098,11 +2097,11 @@
>              if tn is None:
>                  raise error.RepoLookupError(_("tag '%s' does not exist")
>                                              % pattern)
> -            s = set([repo[tn].rev()])
> +            s = {repo[tn].rev()}
>          else:
> -            s = set([cl.rev(n) for t, n in repo.tagslist() if matcher(t)])
> +            s = {cl.rev(n) for t, n in repo.tagslist() if matcher(t)}
>      else:
> -        s = set([cl.rev(n) for t, n in repo.tagslist() if t != 'tip'])
> +        s = {cl.rev(n) for t, n in repo.tagslist() if t != 'tip'}
>      return subset & s
>
>  @predicate('tagged', safe=True)
> diff --git a/mercurial/revsetlang.py b/mercurial/revsetlang.py
> --- a/mercurial/revsetlang.py
> +++ b/mercurial/revsetlang.py
> @@ -44,9 +44,9 @@
>      "end": (0, None, None, None, None),
>  }
>
> -keywords = set(['and', 'or', 'not'])
> +keywords = {'and', 'or', 'not'}
>
> -_quoteletters = set(['"', "'"])
> +_quoteletters = {'"', "'"}
>  _simpleopletters = set(pycompat.iterbytestr("():=,-|&+!~^%"))
>
>  # default set of valid characters for the initial letter of symbols
> diff --git a/mercurial/server.py b/mercurial/server.py
> --- a/mercurial/server.py
> +++ b/mercurial/server.py
> @@ -123,7 +123,7 @@
>      if opts.get('port'):
>          opts['port'] = util.getport(opts.get('port'))
>
> -    alluis = set([ui])
> +    alluis = {ui}
>      if repo:
>          baseui = repo.baseui
>          alluis.update([repo.baseui, repo.ui])
> diff --git a/mercurial/setdiscovery.py b/mercurial/setdiscovery.py
> --- a/mercurial/setdiscovery.py
> +++ b/mercurial/setdiscovery.py
> @@ -243,7 +243,7 @@
>              raise error.Abort(_("repository is unrelated"))
>          else:
>              ui.warn(_("warning: repository is unrelated\n"))
> -        return (set([nullid]), True, srvheadhashes,)
> +        return ({nullid}, True, srvheadhashes,)
>
>      anyincoming = (srvheadhashes != [nullid])
>      return dag.externalizeall(result), anyincoming, srvheadhashes
> diff --git a/mercurial/sslutil.py b/mercurial/sslutil.py
> --- a/mercurial/sslutil.py
> +++ b/mercurial/sslutil.py
> @@ -29,17 +29,17 @@
>  # modern/secure or legacy/insecure. Many operations in this module have
>  # separate code paths depending on support in Python.
>
> -configprotocols = set([
> +configprotocols = {
>      'tls1.0',
>      'tls1.1',
>      'tls1.2',
> -])
> +}
>
>  hassni = getattr(ssl, 'HAS_SNI', False)
>
>  # TLS 1.1 and 1.2 may not be supported if the OpenSSL Python is compiled
>  # against doesn't support them.
> -supportedprotocols = set(['tls1.0'])
> +supportedprotocols = {'tls1.0'}
>  if util.safehasattr(ssl, 'PROTOCOL_TLSv1_1'):
>      supportedprotocols.add('tls1.1')
>  if util.safehasattr(ssl, 'PROTOCOL_TLSv1_2'):
> @@ -296,7 +296,7 @@
>      # disable protocols via SSLContext.options and OP_NO_* constants.
>      # However, SSLContext.options doesn't work unless we have the
>      # full/real SSLContext available to us.
> -    if supportedprotocols == set(['tls1.0']):
> +    if supportedprotocols == {'tls1.0'}:
>          if protocol != 'tls1.0':
>              raise error.Abort(_('current Python does not support protocol '
>                                  'setting %s') % protocol,
> @@ -430,7 +430,7 @@
>                      # is really old. (e.g. server doesn't support TLS 1.0+ or
>                      # client doesn't support modern TLS versions introduced
>                      # several years from when this comment was written).
> -                    if supportedprotocols != set(['tls1.0']):
> +                    if supportedprotocols != {'tls1.0'}:
>                          ui.warn(_(
>                              '(could not communicate with %s using security '
>                              'protocols %s; if you are using a modern Mercurial '
> diff --git a/mercurial/statprof.py b/mercurial/statprof.py
> --- a/mercurial/statprof.py
> +++ b/mercurial/statprof.py
> @@ -126,14 +126,14 @@
>
>  __all__ = ['start', 'stop', 'reset', 'display', 'profile']
>
> -skips = set(["util.py:check", "extensions.py:closure",
> -             "color.py:colorcmd", "dispatch.py:checkargs",
> -             "dispatch.py:<lambda>", "dispatch.py:_runcatch",
> -             "dispatch.py:_dispatch", "dispatch.py:_runcommand",
> -             "pager.py:pagecmd", "dispatch.py:run",
> -             "dispatch.py:dispatch", "dispatch.py:runcommand",
> -             "hg.py:<module>", "evolve.py:warnobserrors",
> -         ])
> +skips = {"util.py:check", "extensions.py:closure",
> +         "color.py:colorcmd", "dispatch.py:checkargs",
> +         "dispatch.py:<lambda>", "dispatch.py:_runcatch",
> +         "dispatch.py:_dispatch", "dispatch.py:_runcommand",
> +         "pager.py:pagecmd", "dispatch.py:run",
> +         "dispatch.py:dispatch", "dispatch.py:runcommand",
> +         "hg.py:<module>", "evolve.py:warnobserrors",
> +}
>
>  ###########################################################################
>  ## Utils
> diff --git a/mercurial/transaction.py b/mercurial/transaction.py
> --- a/mercurial/transaction.py
> +++ b/mercurial/transaction.py
> @@ -26,10 +26,10 @@
>  # These are the file generators that should only be executed after the
>  # finalizers are done, since they rely on the output of the finalizers (like
>  # the changelog having been written).
> -postfinalizegenerators = set([
> +postfinalizegenerators = {
>      'bookmarks',
>      'dirstate'
> -])
> +}
>
>  gengroupall='all'
>  gengroupprefinalize='prefinalize'
> diff --git a/mercurial/upgrade.py b/mercurial/upgrade.py
> --- a/mercurial/upgrade.py
> +++ b/mercurial/upgrade.py
> @@ -28,12 +28,12 @@
>      An upgrade will not be allowed if the repository doesn't have the
>      requirements returned by this function.
>      """
> -    return set([
> +    return {
>          # Introduced in Mercurial 0.9.2.
>          'revlogv1',
>          # Introduced in Mercurial 0.9.2.
>          'store',
> -    ])
> +    }
>
>  def blocksourcerequirements(repo):
>      """Obtain requirements that will prevent an upgrade from occurring.
> @@ -41,7 +41,7 @@
>      An upgrade cannot be performed if the source repository contains a
>      requirements in the returned set.
>      """
> -    return set([
> +    return {
>          # The upgrade code does not yet support these experimental features.
>          # This is an artificial limitation.
>          'manifestv2',
> @@ -51,7 +51,7 @@
>          'parentdelta',
>          # Upgrade should operate on the actual store, not the shared link.
>          'shared',
> -    ])
> +    }
>
>  def supportremovedrequirements(repo):
>      """Obtain requirements that can be removed during an upgrade.
> @@ -70,13 +70,13 @@
>
>      Extensions should monkeypatch this to add their custom requirements.
>      """
> -    return set([
> +    return {
>          'dotencode',
>          'fncache',
>          'generaldelta',
>          'revlogv1',
>          'store',
> -    ])
> +    }
>
>  def allowednewrequirements(repo):
>      """Obtain requirements that can be added to a repository during upgrade.
> @@ -88,11 +88,11 @@
>      bad additions because the whitelist approach is safer and will prevent
>      future, unknown requirements from accidentally being added.
>      """
> -    return set([
> +    return {
>          'dotencode',
>          'fncache',
>          'generaldelta',
> -    ])
> +    }
>
>  deficiency = 'deficiency'
>  optimisation = 'optimization'
> @@ -628,7 +628,7 @@
>      ui.write(_('marking source repository as being upgraded; clients will be '
>                 'unable to read from repository\n'))
>      scmutil.writerequires(srcrepo.vfs,
> -                          srcrepo.requirements | set(['upgradeinprogress']))
> +                          srcrepo.requirements | {'upgradeinprogress'})
>
>      ui.write(_('starting in-place swap of repository data\n'))
>      ui.write(_('replaced files will be backed up at %s\n') %
> diff --git a/mercurial/util.py b/mercurial/util.py
> --- a/mercurial/util.py
> +++ b/mercurial/util.py
> @@ -1097,7 +1097,7 @@
>      return check
>
>  # a whilelist of known filesystems where hardlink works reliably
> -_hardlinkfswhitelist = set([
> +_hardlinkfswhitelist = {
>      'btrfs',
>      'ext2',
>      'ext3',
> @@ -1109,7 +1109,7 @@
>      'ufs',
>      'xfs',
>      'zfs',
> -])
> +}
>
>  def copyfile(src, dest, hardlink=False, copystat=False, checkambig=False):
>      '''copy a file, preserving mode and optionally other stat info like
> diff --git a/mercurial/windows.py b/mercurial/windows.py
> --- a/mercurial/windows.py
> +++ b/mercurial/windows.py
> @@ -334,7 +334,7 @@
>              return executable
>      return findexisting(os.path.expanduser(os.path.expandvars(command)))
>
> -_wantedkinds = set([stat.S_IFREG, stat.S_IFLNK])
> +_wantedkinds = {stat.S_IFREG, stat.S_IFLNK}
>
>  def statfiles(files):
>      '''Stat each file in files. Yield each stat, or None if a file
> diff --git a/mercurial/wireproto.py b/mercurial/wireproto.py
> --- a/mercurial/wireproto.py
> +++ b/mercurial/wireproto.py
> @@ -759,7 +759,7 @@
>              caps.append('stream-preferred')
>          requiredformats = repo.requirements & repo.supportedformats
>          # if our local revlogs are just revlogv1, add 'stream' cap
> -        if not requiredformats - set(('revlogv1',)):
> +        if not requiredformats - {'revlogv1'}:
>              caps.append('stream')
>          # otherwise, add 'streamreqs' detailing our local revlog format
>          else:
> diff --git a/tests/check-perf-code.py b/tests/check-perf-code.py
> --- a/tests/check-perf-code.py
> +++ b/tests/check-perf-code.py
> @@ -26,7 +26,7 @@
>      replacement = [('.py', ''), ('.c', ''), # trim suffix
>                     ('mercurial%s' % (os.sep), ''), # trim "mercurial/" path
>                    ]
> -    ignored = set(['__init__'])
> +    ignored = {'__init__'}
>      modules = {}
>
>      # convert from file name to module name, and count # of appearances
> diff --git a/tests/drawdag.py b/tests/drawdag.py
> --- a/tests/drawdag.py
> +++ b/tests/drawdag.py
> @@ -145,7 +145,7 @@
>      def parents(y, x):
>          """(int, int) -> [str]. follow the ASCII edges at given position,
>          return a list of parents"""
> -        visited = set([(y, x)])
> +        visited = {(y, x)}
>          visit = []
>          result = []
>
> diff --git a/tests/generate-working-copy-states.py b/tests/generate-working-copy-states.py
> --- a/tests/generate-working-copy-states.py
> +++ b/tests/generate-working-copy-states.py
> @@ -47,7 +47,7 @@
>                                   content in parentcontents]) + "-" + tracked
>              yield (filename, parentcontents)
>      else:
> -        for content in (set([None, 'content' + str(depth + 1)]) |
> +        for content in ({None, 'content' + str(depth + 1)} |
>                        set(parentcontents)):
>              for combination in generatestates(maxchangesets,
>                                                parentcontents + [content]):
> diff --git a/tests/test-ancestor.py b/tests/test-ancestor.py
> --- a/tests/test-ancestor.py
> +++ b/tests/test-ancestor.py
> @@ -49,7 +49,7 @@
>  def buildancestorsets(graph):
>      ancs = [None] * len(graph)
>      for i in xrange(len(graph)):
> -        ancs[i] = set([i])
> +        ancs[i] = {i}
>          if graph[i] == [nullrev]:
>              continue
>          for p in graph[i]:
> diff --git a/tests/test-duplicateoptions.py b/tests/test-duplicateoptions.py
> --- a/tests/test-duplicateoptions.py
> +++ b/tests/test-duplicateoptions.py
> @@ -6,7 +6,7 @@
>      ui as uimod,
>  )
>
> -ignore = set(['highlight', 'win32text', 'factotum'])
> +ignore = {'highlight', 'win32text', 'factotum'}
>
>  if os.name != 'nt':
>      ignore.add('win32mbcs')
> diff --git a/tests/test-histedit-fold.t b/tests/test-histedit-fold.t
> --- a/tests/test-histedit-fold.t
> +++ b/tests/test-histedit-fold.t
> @@ -154,7 +154,7 @@
>    > from mercurial import util
>    > def abortfolding(ui, repo, hooktype, **kwargs):
>    >     ctx = repo[kwargs.get('node')]
> -  >     if set(ctx.files()) == set(['c', 'd', 'f']):
> +  >     if set(ctx.files()) == {'c', 'd', 'f'}:
>    >         return True # abort folding commit only
>    >     ui.warn('allow non-folding commit\\n')
>    > EOF
> diff --git a/tests/test-requires.t b/tests/test-requires.t
> --- a/tests/test-requires.t
> +++ b/tests/test-requires.t
> @@ -37,7 +37,7 @@
>    >     for name, module in extensions.extensions(ui):
>    >         if __name__ == module.__name__:
>    >             # support specific feature locally
> -  >             supported |= set(['featuresetup-test'])
> +  >             supported |= {'featuresetup-test'}
>    >             return
>    > def uisetup(ui):
>    >     localrepo.localrepository.featuresetupfuncs.add(featuresetup)
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


More information about the Mercurial-devel mailing list