diff mercurial/wireprotoframing.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 1a612f9ec2c4
line wrap: on
line diff
--- a/mercurial/wireprotoframing.py	Sun Jan 05 22:23:31 2025 -0500
+++ b/mercurial/wireprotoframing.py	Sun Jan 05 22:26:16 2025 -0500
@@ -627,8 +627,7 @@
         """
 
         if data is None:
-            for frame in self._flush():
-                yield frame
+            yield from self._flush()
             return
 
         data = self._stream.encode(data)
@@ -649,8 +648,7 @@
             return
 
         if len(data) > self._maxsize:
-            for frame in self._flush():
-                yield frame
+            yield from self._flush()
 
             # Now emit frames for the big chunk.
             offset = 0
@@ -679,8 +677,7 @@
         # Else flush what we have and buffer the new chunk. We could do
         # something more intelligent here, like break the chunk. Let's
         # keep things simple for now.
-        for frame in self._flush():
-            yield frame
+        yield from self._flush()
 
         self._chunks.append(data)
         self._chunkssize = len(data)
@@ -1303,8 +1300,7 @@
         # If we buffered all our responses, emit those.
         def makegen():
             for gen in self._bufferedframegens:
-                for frame in gen:
-                    yield frame
+                yield from gen
 
         return b'sendframes', {
             b'framegen': makegen(),
@@ -1323,10 +1319,9 @@
         ensureserverstream(stream)
 
         def sendframes():
-            for frame in createerrorframe(
+            yield from createerrorframe(
                 stream, requestid, msg, errtype=b'server'
-            ):
-                yield frame
+            )
 
             self._activecommands.remove(requestid)
 
@@ -1337,10 +1332,9 @@
         ensureserverstream(stream)
 
         def sendframes():
-            for frame in createcommanderrorresponse(
+            yield from createcommanderrorresponse(
                 stream, requestid, message, args
-            ):
-                yield frame
+            )
 
             self._activecommands.remove(requestid)
 
@@ -1856,8 +1850,7 @@
         def makeframes():
             while self._pendingrequests:
                 request = self._pendingrequests.popleft()
-                for frame in self._makecommandframes(request):
-                    yield frame
+                yield from self._makecommandframes(request)
 
         return b'sendframes', {
             b'framegen': makeframes(),
@@ -1899,8 +1892,7 @@
             redirect=request.redirect,
         )
 
-        for frame in res:
-            yield frame
+        yield from res
 
         request.state = b'sent'