Mercurial > public > mercurial-scm > hg-stable
diff mercurial/utils/cborutil.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 | fb8932685031 |
children | 279e217d6041 |
line wrap: on
line diff
--- 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