pyupgrade: use set literals where possible
authorMatt Harbison <matt_harbison@yahoo.com>
Mon, 06 Jan 2025 01:33:08 -0500
changeset 52651 f066fc0bdc7a
parent 52650 b95b12cb31e2
child 52652 0e713555ecdc
pyupgrade: use set literals where possible This was rewritten by the `set_literals` fixer in `pyupgrade`. I thought there was a past change around using set literals, but I can't find it now.
contrib/perf-utils/subsetmaker.py
contrib/python-zstandard/setup_zstd.py
hgext/journal.py
mercurial/branchmap.py
mercurial/revlogutils/rewrite.py
mercurial/scmutil.py
mercurial/upgrade_utils/actions.py
mercurial/utils/storageutil.py
tests/test-doctest.py
--- a/contrib/perf-utils/subsetmaker.py	Mon Jan 06 01:27:42 2025 -0500
+++ b/contrib/perf-utils/subsetmaker.py	Mon Jan 06 01:33:08 2025 -0500
@@ -183,8 +183,8 @@
         selected.add(pick)
         undecided.remove(pick)
 
-        ancestors = set(p for p in parents(pick) if p in undecided)
-        descendants = set(c for c in children(pick) if c in undecided)
+        ancestors = {p for p in parents(pick) if p in undecided}
+        descendants = {c for c in children(pick) if c in undecided}
 
         while ancestors:
             current = ancestors.pop()
--- a/contrib/python-zstandard/setup_zstd.py	Mon Jan 06 01:27:42 2025 -0500
+++ b/contrib/python-zstandard/setup_zstd.py	Mon Jan 06 01:33:08 2025 -0500
@@ -134,7 +134,7 @@
     actual_root = os.path.abspath(os.path.dirname(__file__))
     root = root or actual_root
 
-    sources = set([os.path.join(actual_root, p) for p in ext_sources])
+    sources = {os.path.join(actual_root, p) for p in ext_sources}
     if not system_zstd:
         sources.update([os.path.join(actual_root, p) for p in zstd_sources])
         if support_legacy:
@@ -143,7 +143,7 @@
             )
     sources = list(sources)
 
-    include_dirs = set([os.path.join(actual_root, d) for d in ext_includes])
+    include_dirs = {os.path.join(actual_root, d) for d in ext_includes}
     if not system_zstd:
         from distutils import sysconfig
         from shlex import quote
--- a/hgext/journal.py	Mon Jan 06 01:27:42 2025 -0500
+++ b/hgext/journal.py	Mon Jan 06 01:33:08 2025 -0500
@@ -131,7 +131,7 @@
     repo = store._repo
     if hasattr(repo, 'journal'):
         oldmarks = bookmarks.bmstore(repo)
-        all_marks = set(b for b, n in oldmarks.items())
+        all_marks = {b for b, n in oldmarks.items()}
         all_marks.update(b for b, n in store.items())
         for mark in sorted(all_marks):
             value = store.get(mark, repo.nullid)
--- a/mercurial/branchmap.py	Mon Jan 06 01:27:42 2025 -0500
+++ b/mercurial/branchmap.py	Mon Jan 06 01:33:08 2025 -0500
@@ -915,7 +915,7 @@
         if self._pure_topo_branch is None:
             # we match using node because it is faster to built the set of node
             # than to resolve node → rev later.
-            topo_heads = set(to_node(r) for r in self._get_topo_heads(repo))
+            topo_heads = {to_node(r) for r in self._get_topo_heads(repo)}
         for label, nodes in sorted(self._entries.items()):
             if label == self._pure_topo_branch:
                 # not need to write anything the header took care of that
--- a/mercurial/revlogutils/rewrite.py	Mon Jan 06 01:27:42 2025 -0500
+++ b/mercurial/revlogutils/rewrite.py	Mon Jan 06 01:33:08 2025 -0500
@@ -60,7 +60,7 @@
     # avoid cycle
     from .. import revlog
 
-    censor_revs = set(rl.rev(node) for node in censor_nodes)
+    censor_revs = {rl.rev(node) for node in censor_nodes}
     tombstone = storageutil.packmeta({b'censored': tombstone}, b'')
 
     # Rewriting the revlog in place is hard. Our strategy for censoring is
@@ -732,9 +732,9 @@
                 continue
             filenodes, filename = line.split(b' ', 1)
             fl = _filelog_from_filename(repo, filename)
-            to_fix = set(
+            to_fix = {
                 fl.rev(binascii.unhexlify(n)) for n in filenodes.split(b',')
-            )
+            }
             excluded = set()
 
             for filerev in to_fix:
--- a/mercurial/scmutil.py	Mon Jan 06 01:27:42 2025 -0500
+++ b/mercurial/scmutil.py	Mon Jan 06 01:33:08 2025 -0500
@@ -454,8 +454,8 @@
         obs_set = obs_set - cl.filteredrevs
     if max_rev < (len(cl) - 1):
         # there might be revision to filter out
-        filtered_set = set(r for r in filtered_set if r <= max_rev)
-        obs_set = set(r for r in obs_set if r <= max_rev)
+        filtered_set = {r for r in filtered_set if r <= max_rev}
+        obs_set = {r for r in obs_set if r <= max_rev}
     return (filtered_set, obs_set)
 
 
--- a/mercurial/upgrade_utils/actions.py	Mon Jan 06 01:27:42 2025 -0500
+++ b/mercurial/upgrade_utils/actions.py	Mon Jan 06 01:33:08 2025 -0500
@@ -786,7 +786,7 @@
 
     @property
     def upgrade_actions_names(self):
-        return set([a.name for a in self.upgrade_actions])
+        return {a.name for a in self.upgrade_actions}
 
     @property
     def requirements_only(self):
--- a/mercurial/utils/storageutil.py	Mon Jan 06 01:27:42 2025 -0500
+++ b/mercurial/utils/storageutil.py	Mon Jan 06 01:33:08 2025 -0500
@@ -399,7 +399,7 @@
     emitted = set()
     available = set()
     if assumehaveparentrevisions:
-        common_heads = set(p for r in revs for p in parents(r))
+        common_heads = {p for r in revs for p in parents(r)}
         common_heads.difference_update(revs)
         available = store.ancestors(common_heads, inclusive=True)
 
--- a/tests/test-doctest.py	Mon Jan 06 01:27:42 2025 -0500
+++ b/tests/test-doctest.py	Mon Jan 06 01:33:08 2025 -0500
@@ -129,51 +129,49 @@
 # Meta-test: let's make sure that we actually ran what we expected to, above.
 # Each item in the set is a 2-tuple of module name and stringified kwargs passed
 # to testmod.
-expected_mods_tested = set(
-    [
-        ('hgext.convert.convcmd', '{}'),
-        ('hgext.convert.cvsps', '{}'),
-        ('hgext.convert.filemap', '{}'),
-        ('hgext.convert.p4', '{}'),
-        ('hgext.convert.subversion', '{}'),
-        ('hgext.fix', '{}'),
-        ('hgext.mq', '{}'),
-        ('mercurial.changelog', '{}'),
-        ('mercurial.cmdutil', '{}'),
-        ('mercurial.color', '{}'),
-        ('mercurial.dagparser', "{'optionflags': 4}"),
-        ('mercurial.dirstateutils.v2', '{}'),
-        ('mercurial.encoding', '{}'),
-        ('mercurial.fancyopts', '{}'),
-        ('mercurial.formatter', '{}'),
-        ('mercurial.hg', '{}'),
-        ('mercurial.hgweb.hgwebdir_mod', '{}'),
-        ('mercurial.match', '{}'),
-        ('mercurial.mdiff', '{}'),
-        ('mercurial.minirst', '{}'),
-        ('mercurial.parser', '{}'),
-        ('mercurial.patch', '{}'),
-        ('mercurial.pathutil', '{}'),
-        ('mercurial.pycompat', '{}'),
-        ('mercurial.revlogutils.deltas', '{}'),
-        ('mercurial.revset', '{}'),
-        ('mercurial.revsetlang', '{}'),
-        ('mercurial.simplemerge', '{}'),
-        ('mercurial.smartset', '{}'),
-        ('mercurial.store', '{}'),
-        ('mercurial.subrepo', '{}'),
-        ('mercurial.templater', '{}'),
-        ('mercurial.ui', '{}'),
-        ('mercurial.util', "{'testtarget': 'platform'}"),
-        ('mercurial.util', '{}'),
-        ('mercurial.utils.dateutil', '{}'),
-        ('mercurial.utils.stringutil', '{}'),
-        ('mercurial.utils.urlutil', '{}'),
-        ('tests.drawdag', '{}'),
-        ('tests.test-run-tests', '{}'),
-        ('tests.test-url', "{'optionflags': 4}"),
-    ]
-)
+expected_mods_tested = {
+    ('hgext.convert.convcmd', '{}'),
+    ('hgext.convert.cvsps', '{}'),
+    ('hgext.convert.filemap', '{}'),
+    ('hgext.convert.p4', '{}'),
+    ('hgext.convert.subversion', '{}'),
+    ('hgext.fix', '{}'),
+    ('hgext.mq', '{}'),
+    ('mercurial.changelog', '{}'),
+    ('mercurial.cmdutil', '{}'),
+    ('mercurial.color', '{}'),
+    ('mercurial.dagparser', "{'optionflags': 4}"),
+    ('mercurial.dirstateutils.v2', '{}'),
+    ('mercurial.encoding', '{}'),
+    ('mercurial.fancyopts', '{}'),
+    ('mercurial.formatter', '{}'),
+    ('mercurial.hg', '{}'),
+    ('mercurial.hgweb.hgwebdir_mod', '{}'),
+    ('mercurial.match', '{}'),
+    ('mercurial.mdiff', '{}'),
+    ('mercurial.minirst', '{}'),
+    ('mercurial.parser', '{}'),
+    ('mercurial.patch', '{}'),
+    ('mercurial.pathutil', '{}'),
+    ('mercurial.pycompat', '{}'),
+    ('mercurial.revlogutils.deltas', '{}'),
+    ('mercurial.revset', '{}'),
+    ('mercurial.revsetlang', '{}'),
+    ('mercurial.simplemerge', '{}'),
+    ('mercurial.smartset', '{}'),
+    ('mercurial.store', '{}'),
+    ('mercurial.subrepo', '{}'),
+    ('mercurial.templater', '{}'),
+    ('mercurial.ui', '{}'),
+    ('mercurial.util', "{'testtarget': 'platform'}"),
+    ('mercurial.util', '{}'),
+    ('mercurial.utils.dateutil', '{}'),
+    ('mercurial.utils.stringutil', '{}'),
+    ('mercurial.utils.urlutil', '{}'),
+    ('tests.drawdag', '{}'),
+    ('tests.test-run-tests', '{}'),
+    ('tests.test-url', "{'optionflags': 4}"),
+}
 
 unexpectedly_run = mods_tested.difference(expected_mods_tested)
 not_run = expected_mods_tested.difference(mods_tested)