mirror of https://github.com/python/cpython
utilize yield from
This commit is contained in:
parent
075bbb176f
commit
4993cc0a5b
|
@ -606,8 +606,7 @@ class HelpFormatter(object):
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
self._indent()
|
self._indent()
|
||||||
for subaction in get_subactions():
|
yield from get_subactions()
|
||||||
yield subaction
|
|
||||||
self._dedent()
|
self._dedent()
|
||||||
|
|
||||||
def _split_lines(self, text, width):
|
def _split_lines(self, text, width):
|
||||||
|
|
|
@ -430,8 +430,7 @@ class KeysView(MappingView, Set):
|
||||||
return key in self._mapping
|
return key in self._mapping
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
for key in self._mapping:
|
yield from self._mapping
|
||||||
yield key
|
|
||||||
|
|
||||||
KeysView.register(dict_keys)
|
KeysView.register(dict_keys)
|
||||||
|
|
||||||
|
|
|
@ -198,8 +198,7 @@ def as_completed(fs, timeout=None):
|
||||||
waiter = _create_and_install_waiters(fs, _AS_COMPLETED)
|
waiter = _create_and_install_waiters(fs, _AS_COMPLETED)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
for future in finished:
|
yield from finished
|
||||||
yield future
|
|
||||||
|
|
||||||
while pending:
|
while pending:
|
||||||
if timeout is None:
|
if timeout is None:
|
||||||
|
|
|
@ -922,8 +922,7 @@ class Differ:
|
||||||
else:
|
else:
|
||||||
raise ValueError('unknown tag %r' % (tag,))
|
raise ValueError('unknown tag %r' % (tag,))
|
||||||
|
|
||||||
for line in g:
|
yield from g
|
||||||
yield line
|
|
||||||
|
|
||||||
def _dump(self, tag, x, lo, hi):
|
def _dump(self, tag, x, lo, hi):
|
||||||
"""Generate comparison results for a same-tagged range."""
|
"""Generate comparison results for a same-tagged range."""
|
||||||
|
@ -942,8 +941,7 @@ class Differ:
|
||||||
second = self._dump('+', b, blo, bhi)
|
second = self._dump('+', b, blo, bhi)
|
||||||
|
|
||||||
for g in first, second:
|
for g in first, second:
|
||||||
for line in g:
|
yield from g
|
||||||
yield line
|
|
||||||
|
|
||||||
def _fancy_replace(self, a, alo, ahi, b, blo, bhi):
|
def _fancy_replace(self, a, alo, ahi, b, blo, bhi):
|
||||||
r"""
|
r"""
|
||||||
|
@ -997,8 +995,7 @@ class Differ:
|
||||||
# no non-identical "pretty close" pair
|
# no non-identical "pretty close" pair
|
||||||
if eqi is None:
|
if eqi is None:
|
||||||
# no identical pair either -- treat it as a straight replace
|
# no identical pair either -- treat it as a straight replace
|
||||||
for line in self._plain_replace(a, alo, ahi, b, blo, bhi):
|
yield from self._plain_replace(a, alo, ahi, b, blo, bhi)
|
||||||
yield line
|
|
||||||
return
|
return
|
||||||
# no close pair, but an identical pair -- synch up on that
|
# no close pair, but an identical pair -- synch up on that
|
||||||
best_i, best_j, best_ratio = eqi, eqj, 1.0
|
best_i, best_j, best_ratio = eqi, eqj, 1.0
|
||||||
|
@ -1010,8 +1007,7 @@ class Differ:
|
||||||
# identical
|
# identical
|
||||||
|
|
||||||
# pump out diffs from before the synch point
|
# pump out diffs from before the synch point
|
||||||
for line in self._fancy_helper(a, alo, best_i, b, blo, best_j):
|
yield from self._fancy_helper(a, alo, best_i, b, blo, best_j)
|
||||||
yield line
|
|
||||||
|
|
||||||
# do intraline marking on the synch pair
|
# do intraline marking on the synch pair
|
||||||
aelt, belt = a[best_i], b[best_j]
|
aelt, belt = a[best_i], b[best_j]
|
||||||
|
@ -1033,15 +1029,13 @@ class Differ:
|
||||||
btags += ' ' * lb
|
btags += ' ' * lb
|
||||||
else:
|
else:
|
||||||
raise ValueError('unknown tag %r' % (tag,))
|
raise ValueError('unknown tag %r' % (tag,))
|
||||||
for line in self._qformat(aelt, belt, atags, btags):
|
yield from self._qformat(aelt, belt, atags, btags)
|
||||||
yield line
|
|
||||||
else:
|
else:
|
||||||
# the synch pair is identical
|
# the synch pair is identical
|
||||||
yield ' ' + aelt
|
yield ' ' + aelt
|
||||||
|
|
||||||
# pump out diffs from after the synch point
|
# pump out diffs from after the synch point
|
||||||
for line in self._fancy_helper(a, best_i+1, ahi, b, best_j+1, bhi):
|
yield from self._fancy_helper(a, best_i+1, ahi, b, best_j+1, bhi)
|
||||||
yield line
|
|
||||||
|
|
||||||
def _fancy_helper(self, a, alo, ahi, b, blo, bhi):
|
def _fancy_helper(self, a, alo, ahi, b, blo, bhi):
|
||||||
g = []
|
g = []
|
||||||
|
@ -1053,8 +1047,7 @@ class Differ:
|
||||||
elif blo < bhi:
|
elif blo < bhi:
|
||||||
g = self._dump('+', b, blo, bhi)
|
g = self._dump('+', b, blo, bhi)
|
||||||
|
|
||||||
for line in g:
|
yield from g
|
||||||
yield line
|
|
||||||
|
|
||||||
def _qformat(self, aline, bline, atags, btags):
|
def _qformat(self, aline, bline, atags, btags):
|
||||||
r"""
|
r"""
|
||||||
|
|
|
@ -367,8 +367,7 @@ class TokenList(list):
|
||||||
yield (indent + ' !! invalid element in token '
|
yield (indent + ' !! invalid element in token '
|
||||||
'list: {!r}'.format(token))
|
'list: {!r}'.format(token))
|
||||||
else:
|
else:
|
||||||
for line in token._pp(indent+' '):
|
yield from token._pp(indent+' ')
|
||||||
yield line
|
|
||||||
if self.defects:
|
if self.defects:
|
||||||
extra = ' Defects: {}'.format(self.defects)
|
extra = ' Defects: {}'.format(self.defects)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -26,8 +26,7 @@ def walk(self):
|
||||||
yield self
|
yield self
|
||||||
if self.is_multipart():
|
if self.is_multipart():
|
||||||
for subpart in self.get_payload():
|
for subpart in self.get_payload():
|
||||||
for subsubpart in subpart.walk():
|
yield from subpart.walk()
|
||||||
yield subsubpart
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -40,8 +39,7 @@ def body_line_iterator(msg, decode=False):
|
||||||
for subpart in msg.walk():
|
for subpart in msg.walk():
|
||||||
payload = subpart.get_payload(decode=decode)
|
payload = subpart.get_payload(decode=decode)
|
||||||
if isinstance(payload, str):
|
if isinstance(payload, str):
|
||||||
for line in StringIO(payload):
|
yield from StringIO(payload)
|
||||||
yield line
|
|
||||||
|
|
||||||
|
|
||||||
def typed_subpart_iterator(msg, maintype='text', subtype=None):
|
def typed_subpart_iterator(msg, maintype='text', subtype=None):
|
||||||
|
|
|
@ -26,8 +26,7 @@ def iglob(pathname):
|
||||||
return
|
return
|
||||||
dirname, basename = os.path.split(pathname)
|
dirname, basename = os.path.split(pathname)
|
||||||
if not dirname:
|
if not dirname:
|
||||||
for name in glob1(None, basename):
|
yield from glob1(None, basename)
|
||||||
yield name
|
|
||||||
return
|
return
|
||||||
if has_magic(dirname):
|
if has_magic(dirname):
|
||||||
dirs = iglob(dirname)
|
dirs = iglob(dirname)
|
||||||
|
|
|
@ -631,8 +631,7 @@ class _singlefileMailbox(Mailbox):
|
||||||
def iterkeys(self):
|
def iterkeys(self):
|
||||||
"""Return an iterator over keys."""
|
"""Return an iterator over keys."""
|
||||||
self._lookup()
|
self._lookup()
|
||||||
for key in self._toc.keys():
|
yield from self._toc.keys()
|
||||||
yield key
|
|
||||||
|
|
||||||
def __contains__(self, key):
|
def __contains__(self, key):
|
||||||
"""Return True if the keyed message exists, False otherwise."""
|
"""Return True if the keyed message exists, False otherwise."""
|
||||||
|
|
|
@ -121,8 +121,7 @@ def walk_packages(path=None, prefix='', onerror=None):
|
||||||
# don't traverse path items we've seen before
|
# don't traverse path items we've seen before
|
||||||
path = [p for p in path if not seen(p)]
|
path = [p for p in path if not seen(p)]
|
||||||
|
|
||||||
for item in walk_packages(path, name+'.', onerror):
|
yield from walk_packages(path, name+'.', onerror)
|
||||||
yield item
|
|
||||||
|
|
||||||
|
|
||||||
def iter_modules(path=None, prefix=''):
|
def iter_modules(path=None, prefix=''):
|
||||||
|
|
|
@ -132,8 +132,7 @@ def _iter_chain(exc, custom_tb=None, seen=None):
|
||||||
its.append([(exc, custom_tb or exc.__traceback__)])
|
its.append([(exc, custom_tb or exc.__traceback__)])
|
||||||
# itertools.chain is in an extension module and may be unavailable
|
# itertools.chain is in an extension module and may be unavailable
|
||||||
for it in its:
|
for it in its:
|
||||||
for x in it:
|
yield from it
|
||||||
yield x
|
|
||||||
|
|
||||||
|
|
||||||
def print_exception(etype, value, tb, limit=None, file=None, chain=True):
|
def print_exception(etype, value, tb, limit=None, file=None, chain=True):
|
||||||
|
|
|
@ -153,8 +153,7 @@ class WeakValueDictionary(collections.MutableMapping):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
with _IterationGuard(self):
|
with _IterationGuard(self):
|
||||||
for wr in self.data.values():
|
yield from self.data.values()
|
||||||
yield wr
|
|
||||||
|
|
||||||
def values(self):
|
def values(self):
|
||||||
with _IterationGuard(self):
|
with _IterationGuard(self):
|
||||||
|
|
Loading…
Reference in New Issue