Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4993cc0

Browse files
committed
utilize yield from
1 parent 075bbb1 commit 4993cc0

11 files changed

Lines changed: 18 additions & 36 deletions

File tree

Lib/argparse.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -606,8 +606,7 @@ def _iter_indented_subactions(self, action):
606606
pass
607607
else:
608608
self._indent()
609-
for subaction in get_subactions():
610-
yield subaction
609+
yield from get_subactions()
611610
self._dedent()
612611

613612
def _split_lines(self, text, width):

Lib/collections/abc.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,8 +430,7 @@ def __contains__(self, key):
430430
return key in self._mapping
431431

432432
def __iter__(self):
433-
for key in self._mapping:
434-
yield key
433+
yield from self._mapping
435434

436435
KeysView.register(dict_keys)
437436

Lib/concurrent/futures/_base.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,7 @@ def as_completed(fs, timeout=None):
198198
waiter = _create_and_install_waiters(fs, _AS_COMPLETED)
199199

200200
try:
201-
for future in finished:
202-
yield future
201+
yield from finished
203202

204203
while pending:
205204
if timeout is None:

Lib/difflib.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -922,8 +922,7 @@ def compare(self, a, b):
922922
else:
923923
raise ValueError('unknown tag %r' % (tag,))
924924

925-
for line in g:
926-
yield line
925+
yield from g
927926

928927
def _dump(self, tag, x, lo, hi):
929928
"""Generate comparison results for a same-tagged range."""
@@ -942,8 +941,7 @@ def _plain_replace(self, a, alo, ahi, b, blo, bhi):
942941
second = self._dump('+', b, blo, bhi)
943942

944943
for g in first, second:
945-
for line in g:
946-
yield line
944+
yield from g
947945

948946
def _fancy_replace(self, a, alo, ahi, b, blo, bhi):
949947
r"""
@@ -997,8 +995,7 @@ def _fancy_replace(self, a, alo, ahi, b, blo, bhi):
997995
# no non-identical "pretty close" pair
998996
if eqi is None:
999997
# no identical pair either -- treat it as a straight replace
1000-
for line in self._plain_replace(a, alo, ahi, b, blo, bhi):
1001-
yield line
998+
yield from self._plain_replace(a, alo, ahi, b, blo, bhi)
1002999
return
10031000
# no close pair, but an identical pair -- synch up on that
10041001
best_i, best_j, best_ratio = eqi, eqj, 1.0
@@ -1010,8 +1007,7 @@ def _fancy_replace(self, a, alo, ahi, b, blo, bhi):
10101007
# identical
10111008

10121009
# pump out diffs from before the synch point
1013-
for line in self._fancy_helper(a, alo, best_i, b, blo, best_j):
1014-
yield line
1010+
yield from self._fancy_helper(a, alo, best_i, b, blo, best_j)
10151011

10161012
# do intraline marking on the synch pair
10171013
aelt, belt = a[best_i], b[best_j]
@@ -1033,15 +1029,13 @@ def _fancy_replace(self, a, alo, ahi, b, blo, bhi):
10331029
btags += ' ' * lb
10341030
else:
10351031
raise ValueError('unknown tag %r' % (tag,))
1036-
for line in self._qformat(aelt, belt, atags, btags):
1037-
yield line
1032+
yield from self._qformat(aelt, belt, atags, btags)
10381033
else:
10391034
# the synch pair is identical
10401035
yield ' ' + aelt
10411036

10421037
# pump out diffs from after the synch point
1043-
for line in self._fancy_helper(a, best_i+1, ahi, b, best_j+1, bhi):
1044-
yield line
1038+
yield from self._fancy_helper(a, best_i+1, ahi, b, best_j+1, bhi)
10451039

10461040
def _fancy_helper(self, a, alo, ahi, b, blo, bhi):
10471041
g = []
@@ -1053,8 +1047,7 @@ def _fancy_helper(self, a, alo, ahi, b, blo, bhi):
10531047
elif blo < bhi:
10541048
g = self._dump('+', b, blo, bhi)
10551049

1056-
for line in g:
1057-
yield line
1050+
yield from g
10581051

10591052
def _qformat(self, aline, bline, atags, btags):
10601053
r"""

Lib/email/_header_value_parser.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,7 @@ def _pp(self, indent=''):
367367
yield (indent + ' !! invalid element in token '
368368
'list: {!r}'.format(token))
369369
else:
370-
for line in token._pp(indent+' '):
371-
yield line
370+
yield from token._pp(indent+' ')
372371
if self.defects:
373372
extra = ' Defects: {}'.format(self.defects)
374373
else:

Lib/email/iterators.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ def walk(self):
2626
yield self
2727
if self.is_multipart():
2828
for subpart in self.get_payload():
29-
for subsubpart in subpart.walk():
30-
yield subsubpart
29+
yield from subpart.walk()
3130

3231

3332

@@ -40,8 +39,7 @@ def body_line_iterator(msg, decode=False):
4039
for subpart in msg.walk():
4140
payload = subpart.get_payload(decode=decode)
4241
if isinstance(payload, str):
43-
for line in StringIO(payload):
44-
yield line
42+
yield from StringIO(payload)
4543

4644

4745
def typed_subpart_iterator(msg, maintype='text', subtype=None):

Lib/glob.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ def iglob(pathname):
2626
return
2727
dirname, basename = os.path.split(pathname)
2828
if not dirname:
29-
for name in glob1(None, basename):
30-
yield name
29+
yield from glob1(None, basename)
3130
return
3231
if has_magic(dirname):
3332
dirs = iglob(dirname)

Lib/mailbox.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -631,8 +631,7 @@ def __setitem__(self, key, message):
631631
def iterkeys(self):
632632
"""Return an iterator over keys."""
633633
self._lookup()
634-
for key in self._toc.keys():
635-
yield key
634+
yield from self._toc.keys()
636635

637636
def __contains__(self, key):
638637
"""Return True if the keyed message exists, False otherwise."""

Lib/pkgutil.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,7 @@ def seen(p, m={}):
121121
# don't traverse path items we've seen before
122122
path = [p for p in path if not seen(p)]
123123

124-
for item in walk_packages(path, name+'.', onerror):
125-
yield item
124+
yield from walk_packages(path, name+'.', onerror)
126125

127126

128127
def iter_modules(path=None, prefix=''):

Lib/traceback.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,7 @@ def _iter_chain(exc, custom_tb=None, seen=None):
132132
its.append([(exc, custom_tb or exc.__traceback__)])
133133
# itertools.chain is in an extension module and may be unavailable
134134
for it in its:
135-
for x in it:
136-
yield x
135+
yield from it
137136

138137

139138
def print_exception(etype, value, tb, limit=None, file=None, chain=True):

0 commit comments

Comments
 (0)