diff mercurial/manifest.py @ 52669:e627cc25b6f3

pyupgrade: rewrite `yield` statements in a loop to `yield from` This is the `legacy` fixer in `pyupgrade`, with the `yield` statement yielding loop commented back in. This seems to help pytype in some cases, and hurt it in others. But that can be manually fixed later. Note that it's possibly buggy in that it aggressively changed `import-checker.py` to `yield from 'fcntl', 'grp', 'pwd', 'select', 'termios': # Unix only`, which is invalid syntax. Possibly it needed help from the token fixer that I've disabled locally (because that wants to make a bunch of unrelated changes). Just change those few places to yield from a list, to avoid having to constantly revert that.
author Matt Harbison <matt_harbison@yahoo.com>
date Sun, 05 Jan 2025 22:26:16 -0500
parents 5cc8deb96b48
children 4cb75772818d
line wrap: on
line diff
--- a/mercurial/manifest.py	Sun Jan 05 22:23:31 2025 -0500
+++ b/mercurial/manifest.py	Sun Jan 05 22:26:16 2025 -0500
@@ -588,8 +588,7 @@
         It also reports nonexistent files by marking them bad with match.bad().
         """
         if match.always():
-            for f in iter(self):
-                yield f
+            yield from iter(self)
             return
 
         fset = set(match.files())
@@ -1006,8 +1005,7 @@
             if p in self._files:
                 yield self._subpath(p), n, self._flags.get(p, b'')
             else:
-                for x in n.iterentries():
-                    yield x
+                yield from n.iterentries()
 
     def items(self) -> Iterator[Tuple[bytes, Union[bytes, 'treemanifest']]]:
         self._load()
@@ -1018,8 +1016,7 @@
             if p in self._files:
                 yield self._subpath(p), n
             else:
-                for f, sn in n.items():
-                    yield f, sn
+                yield from n.items()
 
     iteritems = items
 
@@ -1030,8 +1027,7 @@
             if p in self._files:
                 yield self._subpath(p)
             else:
-                for f in self._dirs[p]:
-                    yield f
+                yield from self._dirs[p]
 
     def keys(self) -> List[bytes]:
         return list(self.iterkeys())
@@ -1260,8 +1256,7 @@
         It also reports nonexistent files by marking them bad with match.bad().
         """
         if match.always():
-            for f in iter(self):
-                yield f
+            yield from iter(self)
             return
 
         fset = set(match.files())
@@ -1296,8 +1291,7 @@
                     yield fullp
             else:
                 if not visit or p[:-1] in visit:
-                    for f in self._dirs[p]._walk(match):
-                        yield f
+                    yield from self._dirs[p]._walk(match)
 
     def _matches(self, match: matchmod.basematcher) -> 'treemanifest':
         """recursively generate a new manifest filtered by the match argument."""
@@ -1538,8 +1532,7 @@
         # OPT: use visitchildrenset to avoid loading everything.
         self._loadalllazy()
         for d, subm in self._dirs.items():
-            for subtree in subm.walksubtrees(matcher=matcher):
-                yield subtree
+            yield from subm.walksubtrees(matcher=matcher)
 
 
 class manifestfulltextcache(util.lrucachedict):