diff mercurial/patch.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 279e217d6041
line wrap: on
line diff
--- a/mercurial/patch.py	Sun Jan 05 22:23:31 2025 -0500
+++ b/mercurial/patch.py	Sun Jan 05 22:26:16 2025 -0500
@@ -94,15 +94,13 @@
     def mboxsplit(stream, cur):
         for line in stream:
             if line.startswith(b'From '):
-                for c in split(chunk(cur[1:])):
-                    yield c
+                yield from split(chunk(cur[1:]))
                 cur = []
 
             cur.append(line)
 
         if cur:
-            for c in split(chunk(cur[1:])):
-                yield c
+            yield from split(chunk(cur[1:]))
 
     def mimesplit(stream, cur):
         def msgfp(m):
@@ -2737,8 +2735,7 @@
             raise error.ProgrammingError(b'unexpected hunk line: %s' % line)
     # fast path: if either side is empty, use diffsinglehunk
     if not a or not b:
-        for t in diffsinglehunk(hunklines):
-            yield t
+        yield from diffsinglehunk(hunklines)
         return
     # re-split the content into words
     al = wordsplitter.findall(bytes(a))
@@ -2824,8 +2821,7 @@
 
     def consumehunkbuffer():
         if hunkbuffer:
-            for token in dodiffhunk(hunkbuffer):
-                yield token
+            yield from dodiffhunk(hunkbuffer)
             hunkbuffer[:] = []
 
     for chunk in func(*args, **kw):
@@ -2855,8 +2851,7 @@
                 hunkbuffer.append(bufferedline)
             else:
                 # unbuffered
-                for token in consumehunkbuffer():
-                    yield token
+                yield from consumehunkbuffer()
                 stripline = line.rstrip()
                 for prefix, label in prefixes:
                     if stripline.startswith(prefix):
@@ -2871,8 +2866,7 @@
                     yield (line, b'')
                 if i + 1 < linecount:
                     yield (b'\n', b'')
-        for token in consumehunkbuffer():
-            yield token
+        yield from consumehunkbuffer()
 
 
 def diffui(*args, **kw):