Mercurial > public > mercurial-scm > hg
changeset 52644: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.
line wrap: on
line diff
--- a/contrib/import-checker.py Sun Jan 05 22:23:31 2025 -0500 +++ b/contrib/import-checker.py Sun Jan 05 22:26:16 2025 -0500 @@ -217,24 +217,19 @@ >>> 'cffi' in mods True """ - for m in sys.builtin_module_names: - yield m + yield from sys.builtin_module_names # These modules only exist on windows, but we should always # consider them stdlib. - for m in ['msvcrt', '_winreg']: - yield m + yield from ['msvcrt', '_winreg'] yield '__builtin__' yield 'builtins' # python3 only yield 'importlib.abc' # python3 only yield 'importlib.machinery' # python3 only yield 'importlib.util' # python3 only yield 'packaging.version' - for m in 'fcntl', 'grp', 'pwd', 'select', 'termios': # Unix only - yield m - for m in 'cPickle', 'datetime': # in Python (not C) on PyPy - yield m - for m in ['cffi']: - yield m + yield from ['fcntl', 'grp', 'pwd', 'select', 'termios'] + yield from ['cPickle', 'datetime'] + yield from ['cffi'] yield 'distutils' # in Python < 3.12 yield 'distutils.version' # in Python < 3.12 stdlib_prefixes = {sys.prefix, sys.exec_prefix} @@ -443,10 +438,9 @@ if newscope: # Check for local imports in function - for r in verify_modern_convention( + yield from verify_modern_convention( module, node, localmods, node.col_offset + 4 - ): - yield r + ) elif isinstance(node, ast.Import): # Disallow "import foo, bar" and require separate imports # for each module.
--- a/hgext/git/manifest.py Sun Jan 05 22:23:31 2025 -0500 +++ b/hgext/git/manifest.py Sun Jan 05 22:26:16 2025 -0500 @@ -277,10 +277,9 @@ # TODO: can we prune dir walks with the matcher? realname = subdir + pycompat.fsencode(te.name) if te.type == pygit2.GIT_OBJ_TREE: - for inner in self._walkonetree( + yield from self._walkonetree( self._git_repo[te.id], match, realname + b'/' - ): - yield inner + ) elif match(realname): yield pycompat.fsencode(realname)
--- a/hgext/gpg.py Sun Jan 05 22:23:31 2025 -0500 +++ b/hgext/gpg.py Sun Jan 05 22:26:16 2025 -0500 @@ -160,13 +160,11 @@ fl = repo.file(b".hgsigs") for r in reversed(fl.heads()): fn = b".hgsigs|%s" % short(r) - for item in parsefile(fl.read(r).splitlines(), fn): - yield item + yield from parsefile(fl.read(r).splitlines(), fn) try: # read local signatures fn = b"localsigs" - for item in parsefile(repo.vfs(fn), fn): - yield item + yield from parsefile(repo.vfs(fn), fn) except OSError: pass
--- a/hgext/keyword.py Sun Jan 05 22:23:31 2025 -0500 +++ b/hgext/keyword.py Sun Jan 05 22:26:16 2025 -0500 @@ -674,8 +674,7 @@ restrict = kwt.restrict kwt.restrict = True try: - for chunk in orig(repo, *args, **kwargs): - yield chunk + yield from orig(repo, *args, **kwargs) finally: if kwt: kwt.restrict = restrict @@ -688,8 +687,7 @@ origmatch = kwt.match kwt.match = util.never try: - for chunk in orig(web): - yield chunk + yield from orig(web) finally: if kwt: kwt.match = origmatch
--- a/hgext/largefiles/proto.py Sun Jan 05 22:23:31 2025 -0500 +++ b/hgext/largefiles/proto.py Sun Jan 05 22:26:16 2025 -0500 @@ -83,8 +83,7 @@ # ssh proto does for string responses. def generator(): yield b'%d\n' % length - for chunk in util.filechunkiter(f): - yield chunk + yield from util.filechunkiter(f) return wireprototypes.streamreslegacy(gen=generator())
--- a/hgext/remotefilelog/remotefilectx.py Sun Jan 05 22:23:31 2025 -0500 +++ b/hgext/remotefilelog/remotefilectx.py Sun Jan 05 22:26:16 2025 -0500 @@ -405,8 +405,7 @@ # The copy tracing algorithm depends on these coming out in order ancestors = sorted(ancestors, reverse=True, key=lambda x: x.linkrev()) - for ancestor in ancestors: - yield ancestor + yield from ancestors def ancestor(self, fc2, actx): # the easy case: no (relevant) renames
--- a/hgext/remotefilelog/remotefilelogserver.py Sun Jan 05 22:23:31 2025 -0500 +++ b/hgext/remotefilelog/remotefilelogserver.py Sun Jan 05 22:26:16 2025 -0500 @@ -131,8 +131,7 @@ def gen(): yield first yield second - for value in streamres.gen: - yield value + yield from streamres.gen return wireprototypes.streamres(gen()) finally:
--- a/hgext/remotefilelog/shallowbundle.py Sun Jan 05 22:23:31 2025 -0500 +++ b/hgext/remotefilelog/shallowbundle.py Sun Jan 05 22:26:16 2025 -0500 @@ -29,8 +29,7 @@ def shallowgroup(cls, self, nodelist, rlog, lookup, units=None, reorder=None): if not isinstance(rlog, remotefilelog.remotefilelog): - for c in super(cls, self).group(nodelist, rlog, lookup, units=units): - yield c + yield from super(cls, self).group(nodelist, rlog, lookup, units=units) return if len(nodelist) == 0: @@ -47,8 +46,7 @@ for i in range(len(nodelist) - 1): prev, curr = nodelist[i], nodelist[i + 1] linknode = lookup(curr) - for c in self.nodechunk(rlog, curr, prev, linknode): - yield c + yield from self.nodechunk(rlog, curr, prev, linknode) yield self.close()
--- a/hgext/sqlitestore.py Sun Jan 05 22:23:31 2025 -0500 +++ b/hgext/sqlitestore.py Sun Jan 05 22:26:16 2025 -0500 @@ -648,7 +648,7 @@ deltabases[rev] = res.fetchone()[0] # TODO define revdifffn so we can use delta from storage. - for delta in storageutil.emitrevisions( + yield from storageutil.emitrevisions( self, nodes, nodesorder, @@ -658,8 +658,7 @@ assumehaveparentrevisions=assumehaveparentrevisions, deltamode=deltamode, sidedata_helpers=sidedata_helpers, - ): - yield delta + ) # End of ifiledata interface.
--- a/mercurial/bundle2.py Sun Jan 05 22:23:31 2025 -0500 +++ b/mercurial/bundle2.py Sun Jan 05 22:26:16 2025 -0500 @@ -753,10 +753,9 @@ yield _pack(_fstreamparamsize, len(param)) if param: yield param - for chunk in self._compengine.compressstream( + yield from self._compengine.compressstream( self._getcorechunk(), self._compopts - ): - yield chunk + ) def _paramchunk(self): """return a encoded version of all stream parameters""" @@ -776,8 +775,7 @@ outdebug(self.ui, b'start of parts') for part in self._parts: outdebug(self.ui, b'bundle part: "%s"' % part.type) - for chunk in part.getchunks(ui=self.ui): - yield chunk + yield from part.getchunks(ui=self.ui) outdebug(self.ui, b'end of bundle') yield _pack(_fpartheadersize, 0) @@ -1861,10 +1859,8 @@ utf8branch = encoding.fromlocal(branch) yield rbcstruct.pack(len(utf8branch), len(nodes), len(closed)) yield utf8branch - for n in sorted(nodes): - yield n - for n in sorted(closed): - yield n + yield from sorted(nodes) + yield from sorted(closed) bundler.newpart(b'cache:rev-branch-cache', data=generate(), mandatory=False) @@ -2033,8 +2029,7 @@ def chunkiter(): yield header - for chunk in compengine.compressstream(cg.getchunks(), compopts): - yield chunk + yield from compengine.compressstream(cg.getchunks(), compopts) chunkiter = chunkiter()
--- a/mercurial/cmdutil.py Sun Jan 05 22:23:31 2025 -0500 +++ b/mercurial/cmdutil.py Sun Jan 05 22:26:16 2025 -0500 @@ -792,13 +792,11 @@ return # add the files to status list - for st, fpath in self.iterfilepaths(): - yield st, fpath + yield from self.iterfilepaths() # recurse on the subdirs for dirobj in self.subdirs.values(): - for st, fpath in dirobj.tersewalk(terseargs): - yield st, fpath + yield from dirobj.tersewalk(terseargs) def tersedir(statuslist: istatus.Status, terseargs) -> istatus.Status:
--- a/mercurial/config.py Sun Jan 05 22:23:31 2025 -0500 +++ b/mercurial/config.py Sun Jan 05 22:26:16 2025 -0500 @@ -52,8 +52,7 @@ return self._data.get(section, {}) def __iter__(self): - for d in self.sections(): - yield d + yield from self.sections() def update(self, src): current_level = self._current_source_level
--- a/mercurial/context.py Sun Jan 05 22:23:31 2025 -0500 +++ b/mercurial/context.py Sun Jan 05 22:26:16 2025 -0500 @@ -1534,8 +1534,7 @@ return self._parents[0].ancestor(c2) # punt on two parents for now def ancestors(self): - for p in self._parents: - yield p + yield from self._parents for a in self._repo.changelog.ancestors( [p.rev() for p in self._parents] ):
--- a/mercurial/dagop.py Sun Jan 05 22:23:31 2025 -0500 +++ b/mercurial/dagop.py Sun Jan 05 22:26:16 2025 -0500 @@ -1008,8 +1008,7 @@ # subgroup unblocked |= gr[1] # output all revisions in the subgroup - for r in gr[0]: - yield r + yield from gr[0] # delete the subgroup that you just output # unless it is groups[0] in which case you just empty it. if targetidx: @@ -1019,8 +1018,7 @@ # Check if we have some subgroup waiting for revisions we are not going to # iterate over for g in groups: - for r in g[0]: - yield r + yield from g[0] def headrevs(revs, parentsfn):
--- a/mercurial/hg.py Sun Jan 05 22:23:31 2025 -0500 +++ b/mercurial/hg.py Sun Jan 05 22:26:16 2025 -0500 @@ -1434,8 +1434,7 @@ if opts.get(b'newest_first'): revs.reverse() if limit is None and not no_merges: - for r in revs: - yield r + yield from revs return count = 0
--- a/mercurial/hgweb/hgweb_mod.py Sun Jan 05 22:23:31 2025 -0500 +++ b/mercurial/hgweb/hgweb_mod.py Sun Jan 05 22:26:16 2025 -0500 @@ -361,8 +361,7 @@ with self._obtainrepo() as repo: profile = repo.ui.configbool(b'profiling', b'enabled') with profiling.profile(repo.ui, enabled=profile): - for r in self._runwsgi(req, res, repo): - yield r + yield from self._runwsgi(req, res, repo) def _runwsgi(self, req, res, repo): rctx = requestcontext(self, repo, req, res)
--- a/mercurial/hgweb/hgwebdir_mod.py Sun Jan 05 22:23:31 2025 -0500 +++ b/mercurial/hgweb/hgwebdir_mod.py Sun Jan 05 22:26:16 2025 -0500 @@ -382,8 +382,7 @@ profile = self.ui.configbool(b'profiling', b'enabled') with profiling.profile(self.ui, enabled=profile): try: - for r in self._runwsgi(req, res): - yield r + yield from self._runwsgi(req, res) finally: # There are known cycles in localrepository that prevent # those objects (and tons of held references) from being @@ -452,8 +451,7 @@ def _virtualdirs(): # Check the full virtual path, and each parent yield virtual - for p in pathutil.finddirs(virtual): - yield p + yield from pathutil.finddirs(virtual) for virtualrepo in _virtualdirs(): real = repos.get(virtualrepo)
--- a/mercurial/hgweb/webcommands.py Sun Jan 05 22:23:31 2025 -0500 +++ b/mercurial/hgweb/webcommands.py Sun Jan 05 22:26:16 2025 -0500 @@ -234,8 +234,7 @@ ctx = web.repo[j] l.append(ctx) l.reverse() - for e in l: - yield e + yield from l for ctx in revgen(): miss = 0 @@ -425,8 +424,7 @@ if pos != -1: revs = web.repo.changelog.revs(pos, 0) - for entry in webutil.changelistentries(web, revs, maxcount, parity): - yield entry + yield from webutil.changelistentries(web, revs, maxcount, parity) if shortlog: revcount = web.maxshortchanges @@ -798,8 +796,7 @@ lm[b'parity'] = next(parity) l.append(lm) - for entry in reversed(l): - yield entry + yield from reversed(l) tip = web.repo[b'tip'] count = len(web.repo)
--- a/mercurial/logcmdutil.py Sun Jan 05 22:23:31 2025 -0500 +++ b/mercurial/logcmdutil.py Sun Jan 05 22:26:16 2025 -0500 @@ -1222,8 +1222,7 @@ if any(mdiff.hunkinrange(hr[2:], lr) for lr in lineranges): yield hr, lines else: - for hunk in hunks: - yield hunk + yield from hunks return filterfn
--- a/mercurial/logexchange.py Sun Jan 05 22:23:31 2025 -0500 +++ b/mercurial/logexchange.py Sun Jan 05 22:26:16 2025 -0500 @@ -58,10 +58,8 @@ information, call the respective functions. """ - for bmentry in readremotenamefile(repo, b'bookmarks'): - yield bmentry - for branchentry in readremotenamefile(repo, b'branches'): - yield branchentry + yield from readremotenamefile(repo, b'bookmarks') + yield from readremotenamefile(repo, b'branches') def writeremotenamefile(repo, remotepath, names, nametype):
--- 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):
--- a/mercurial/mdiff.py Sun Jan 05 22:23:31 2025 -0500 +++ b/mercurial/mdiff.py Sun Jan 05 22:26:16 2025 -0500 @@ -529,8 +529,7 @@ if not has_hunks: has_hunks = True yield True - for x in yieldhunk(hunk): - yield x + yield from yieldhunk(hunk) if prev: # we've joined the previous hunk, record the new ending points. hunk = (hunk[0], a2, hunk[2], b2, hunk[4]) @@ -547,8 +546,7 @@ if not has_hunks: has_hunks = True yield True - for x in yieldhunk(hunk): - yield x + yield from yieldhunk(hunk) elif not has_hunks: yield False
--- a/mercurial/merge.py Sun Jan 05 22:23:31 2025 -0500 +++ b/mercurial/merge.py Sun Jan 05 22:26:16 2025 -0500 @@ -634,13 +634,11 @@ # TODO: think whether we should return renamedelete and # diverge filenames also if actions is None: - for f in self._filemapping: - yield f + yield from self._filemapping else: for a in actions: - for f in self._actionmapping[a]: - yield f + yield from self._actionmapping[a] def removefile(self, filename): """removes a file from the mergeresult object as the file might @@ -677,11 +675,9 @@ def filemap(self, sort=False): if sort: - for key, val in sorted(self._filemapping.items()): - yield key, val + yield from sorted(self._filemapping.items()) else: - for key, val in self._filemapping.items(): - yield key, val + yield from self._filemapping.items() def addcommitinfo(self, filename, key, value): """adds key-value information about filename which will be required
--- 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):
--- a/mercurial/revlogutils/deltas.py Sun Jan 05 22:23:31 2025 -0500 +++ b/mercurial/revlogutils/deltas.py Sun Jan 05 22:26:16 2025 -0500 @@ -162,8 +162,7 @@ revlog.data_config.sr_density_threshold, revlog.data_config.sr_min_gap_size, ): - for subchunk in _slicechunktosize(revlog, chunk, targetsize): - yield subchunk + yield from _slicechunktosize(revlog, chunk, targetsize) def _slicechunktosize(revlog, revs, targetsize=None):
--- a/mercurial/revlogutils/nodemap.py Sun Jan 05 22:23:31 2025 -0500 +++ b/mercurial/revlogutils/nodemap.py Sun Jan 05 22:26:16 2025 -0500 @@ -556,8 +556,7 @@ """ for __, item in sorted(block.items()): if isinstance(item, dict): - for sub_block in _walk_trie(item): - yield sub_block + yield from _walk_trie(item) yield block
--- a/mercurial/scmutil.py Sun Jan 05 22:23:31 2025 -0500 +++ b/mercurial/scmutil.py Sun Jan 05 22:26:16 2025 -0500 @@ -514,8 +514,7 @@ fname = os.path.join(root, d) if adddir(seen_dirs, fname): if os.path.islink(fname): - for hgname in walkrepos(fname, True, seen_dirs): - yield hgname + yield from walkrepos(fname, True, seen_dirs) else: newdirs.append(d) dirs[:] = newdirs
--- a/mercurial/smartset.py Sun Jan 05 22:23:31 2025 -0500 +++ b/mercurial/smartset.py Sun Jan 05 22:26:16 2025 -0500 @@ -544,8 +544,7 @@ elif val2 is not None: # might have been equality and both are empty yield val2 - for val in it: - yield val + yield from it class addset(abstractsmartset):
--- a/mercurial/store.py Sun Jan 05 22:23:31 2025 -0500 +++ b/mercurial/store.py Sun Jan 05 22:26:16 2025 -0500 @@ -126,12 +126,9 @@ these characters will be escaped by encodefunctions """ winreserved = [ord(x) for x in '\\:*?"<>|'] - for x in range(32): - yield x - for x in range(126, 256): - yield x - for x in winreserved: - yield x + yield from range(32) + yield from range(126, 256) + yield from winreserved def _buildencodefun(): @@ -928,10 +925,8 @@ are passed with matches the matcher """ # yield data files first - for x in self.data_entries(matcher): - yield x - for x in self.top_entries(phase=phase, obsolescence=obsolescence): - yield x + yield from self.data_entries(matcher) + yield from self.top_entries(phase=phase, obsolescence=obsolescence) def copylist(self): return _data
--- a/mercurial/streamclone.py Sun Jan 05 22:23:31 2025 -0500 +++ b/mercurial/streamclone.py Sun Jan 05 22:26:16 2025 -0500 @@ -303,8 +303,7 @@ if size <= 65536: yield fp.read(size) else: - for chunk in util.filechunkiter(fp, limit=size): - yield chunk + yield from util.filechunkiter(fp, limit=size) return len(entries), total_bytes, emitrevlogdata() @@ -333,8 +332,7 @@ # Indicates successful response. yield b'0\n' yield b'%d %d\n' % (filecount, bytecount) - for chunk in it: - yield chunk + yield from it def generatebundlev1(repo, compression=b'UN'):
--- a/mercurial/templateutil.py Sun Jan 05 22:23:31 2025 -0500 +++ b/mercurial/templateutil.py Sun Jan 05 22:26:16 2025 -0500 @@ -871,8 +871,7 @@ elif not hasattr(i, '__iter__'): yield pycompat.bytestr(i) else: - for j in flatten(context, mapping, i): - yield j + yield from flatten(context, mapping, i) def stringify(context, mapping, thing):
--- a/mercurial/ui.py Sun Jan 05 22:23:31 2025 -0500 +++ b/mercurial/ui.py Sun Jan 05 22:26:16 2025 -0500 @@ -980,8 +980,7 @@ def walkconfig(self, untrusted=False, all_known=False): defined = self._walk_config(untrusted) if not all_known: - for d in defined: - yield d + yield from defined return known = self._walk_known() current_defined = next(defined, None)
--- a/mercurial/util.py Sun Jan 05 22:23:31 2025 -0500 +++ b/mercurial/util.py Sun Jan 05 22:26:16 2025 -0500 @@ -3024,8 +3024,7 @@ def iterlines(iterator: Iterable[bytes]) -> Iterator[bytes]: for chunk in iterator: - for line in chunk.splitlines(): - yield line + yield from chunk.splitlines() def expandpath(path: bytes) -> bytes:
--- a/mercurial/utils/cborutil.py Sun Jan 05 22:23:31 2025 -0500 +++ b/mercurial/utils/cborutil.py Sun Jan 05 22:26:16 2025 -0500 @@ -137,8 +137,7 @@ yield encodelength(MAJOR_TYPE_ARRAY, len(l)) for i in l: - for chunk in streamencode(i): - yield chunk + yield from streamencode(i) def streamencodearrayfromiter(it): @@ -147,8 +146,7 @@ yield BEGIN_INDEFINITE_ARRAY for i in it: - for chunk in streamencode(i): - yield chunk + yield from streamencode(i) yield BREAK @@ -162,8 +160,7 @@ # semantic tag 258 for finite sets. yield encodelength(MAJOR_TYPE_SEMANTIC, SEMANTIC_TAG_FINITE_SET) - for chunk in streamencodearray(sorted(s, key=_mixedtypesortkey)): - yield chunk + yield from streamencodearray(sorted(s, key=_mixedtypesortkey)) def streamencodemap(d): @@ -174,10 +171,8 @@ yield encodelength(MAJOR_TYPE_MAP, len(d)) for key, value in sorted(d.items(), key=lambda x: _mixedtypesortkey(x[0])): - for chunk in streamencode(key): - yield chunk - for chunk in streamencode(value): - yield chunk + yield from streamencode(key) + yield from streamencode(value) def streamencodemapfromiter(it): @@ -185,10 +180,8 @@ yield BEGIN_INDEFINITE_MAP for key, value in it: - for chunk in streamencode(key): - yield chunk - for chunk in streamencode(value): - yield chunk + yield from streamencode(key) + yield from streamencode(value) yield BREAK
--- a/mercurial/utils/stringutil.py Sun Jan 05 22:23:31 2025 -0500 +++ b/mercurial/utils/stringutil.py Sun Jan 05 22:26:16 2025 -0500 @@ -107,10 +107,7 @@ yield b' ' * (level * indent) for i, a in enumerate(o): - for chunk in pprintgen( - a, bprefix=bprefix, indent=indent, level=level - ): - yield chunk + yield from pprintgen(a, bprefix=bprefix, indent=indent, level=level) if i + 1 < len(o): if indent: @@ -138,17 +135,11 @@ yield b' ' * (level * indent) for i, (k, v) in enumerate(sorted(o.items())): - for chunk in pprintgen( - k, bprefix=bprefix, indent=indent, level=level - ): - yield chunk + yield from pprintgen(k, bprefix=bprefix, indent=indent, level=level) yield b': ' - for chunk in pprintgen( - v, bprefix=bprefix, indent=indent, level=level - ): - yield chunk + yield from pprintgen(v, bprefix=bprefix, indent=indent, level=level) if i + 1 < len(o): if indent: @@ -176,10 +167,7 @@ yield b' ' * (level * indent) for i, k in enumerate(sorted(o)): - for chunk in pprintgen( - k, bprefix=bprefix, indent=indent, level=level - ): - yield chunk + yield from pprintgen(k, bprefix=bprefix, indent=indent, level=level) if i + 1 < len(o): if indent: @@ -207,10 +195,7 @@ yield b' ' * (level * indent) for i, a in enumerate(o): - for chunk in pprintgen( - a, bprefix=bprefix, indent=indent, level=level - ): - yield chunk + yield from pprintgen(a, bprefix=bprefix, indent=indent, level=level) if i + 1 < len(o): if indent: @@ -250,10 +235,9 @@ except StopIteration: last = True - for chunk in pprintgen( + yield from pprintgen( current, bprefix=bprefix, indent=indent, level=level - ): - yield chunk + ) if not last: if indent:
--- 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'
--- a/mercurial/wireprotoserver.py Sun Jan 05 22:23:31 2025 -0500 +++ b/mercurial/wireprotoserver.py Sun Jan 05 22:26:16 2025 -0500 @@ -287,8 +287,7 @@ yield struct.pack(b'B', len(name)) yield name - for chunk in gen: - yield chunk + yield from gen def setresponse(code, contenttype, bodybytes=None, bodygen=None): if code == HTTP_OK:
--- a/mercurial/wireprotov1peer.py Sun Jan 05 22:23:31 2025 -0500 +++ b/mercurial/wireprotov1peer.py Sun Jan 05 22:26:16 2025 -0500 @@ -351,8 +351,7 @@ length = util.uvarintdecodestream(stream) # SSH streams will block if reading more than length - for chunk in util.filechunkiter(stream, limit=length): - yield chunk + yield from util.filechunkiter(stream, limit=length) self._finish_inline_clone_bundle(stream)
--- a/mercurial/wireprotov1server.py Sun Jan 05 22:23:31 2025 -0500 +++ b/mercurial/wireprotov1server.py Sun Jan 05 22:26:16 2025 -0500 @@ -292,8 +292,7 @@ with vfs(bundle_path) as f: length = os.fstat(f.fileno())[6] yield util.uvarintencode(length) - for chunk in util.filechunkiter(f): - yield chunk + yield from util.filechunkiter(f) stream = generator(repo.vfs, clonebundlepath) return wireprototypes.streamres(gen=stream, prefer_uncompressed=True)
--- a/tests/generate-working-copy-states.py Sun Jan 05 22:23:31 2025 -0500 +++ b/tests/generate-working-copy-states.py Sun Jan 05 22:26:16 2025 -0500 @@ -58,10 +58,7 @@ for content in {None, b'content' + (b"%d" % (depth + 1))} | set( parentcontents ): - for combination in generatestates( - maxchangesets, parentcontents + [content] - ): - yield combination + yield from generatestates(maxchangesets, parentcontents + [content]) # retrieve the command line arguments
--- a/tests/simplestorerepo.py Sun Jan 05 22:23:31 2025 -0500 +++ b/tests/simplestorerepo.py Sun Jan 05 22:26:16 2025 -0500 @@ -456,7 +456,7 @@ nodes = [n for n in nodes if n != self._repo.nullid] if not nodes: return - for delta in storageutil.emitrevisions( + yield from storageutil.emitrevisions( self, nodes, nodesorder, @@ -465,8 +465,7 @@ assumehaveparentrevisions=assumehaveparentrevisions, deltamode=deltamode, sidedata_helpers=sidedata_helpers, - ): - yield delta + ) def add(self, text, meta, transaction, linkrev, p1, p2): if meta or text.startswith(b'\1\n'): @@ -669,8 +668,7 @@ class simplestore(store.encodedstore): def data_entries(self, undecodable=None): - for x in super().data_entries(): - yield x + yield from super().data_entries() # Supplement with non-revlog files. extrafiles = self._walk('data', True, filefilter=issimplestorefile)