Refs #23919 -- Used yield from.

This commit is contained in:
Vytis Banaitis 2017-02-24 03:06:01 +02:00 committed by Tim Graham
parent 4cffa9a1ff
commit 3dcc351691
19 changed files with 24 additions and 51 deletions

View File

@ -312,8 +312,7 @@ class ListMixin:
def newItems():
for i in range(origLen + 1):
if i == start:
for val in valueList:
yield val
yield from valueList
if i < origLen:
if i < start or i >= stop:

View File

@ -402,9 +402,7 @@ class ManifestFilesMixin(HashedFilesMixin):
def post_process(self, *args, **kwargs):
self.hashed_files = OrderedDict()
all_post_processed = super().post_process(*args, **kwargs)
for post_processed in all_post_processed:
yield post_processed
yield from super().post_process(*args, **kwargs)
self.save_manifest()
def save_manifest(self):

View File

@ -37,8 +37,7 @@ def get_files(storage, ignore_patterns=None, location=''):
continue
if location:
dir = os.path.join(location, dir)
for fn in get_files(storage, ignore_patterns, dir):
yield fn
yield from get_files(storage, ignore_patterns, dir)
def check_settings(base_url=None):

View File

@ -166,8 +166,7 @@ class Command(BaseCommand):
if count_only:
yield queryset.order_by().count()
else:
for obj in queryset.iterator():
yield obj
yield from queryset.iterator()
try:
self.stdout.ending = None

View File

@ -69,8 +69,7 @@ def Deserializer(stream_or_string, **options):
stream_or_string = stream_or_string.decode()
try:
objects = json.loads(stream_or_string)
for obj in PythonDeserializer(objects, **options):
yield obj
yield from PythonDeserializer(objects, **options)
except (GeneratorExit, DeserializationError):
raise
except Exception as exc:

View File

@ -70,8 +70,7 @@ def Deserializer(stream_or_string, **options):
else:
stream = stream_or_string
try:
for obj in PythonDeserializer(yaml.load(stream, Loader=SafeLoader), **options):
yield obj
yield from PythonDeserializer(yaml.load(stream, Loader=SafeLoader), **options)
except (GeneratorExit, DeserializationError):
raise
except Exception as exc:

View File

@ -113,8 +113,7 @@ class BaseDatabaseCreation:
if (model._meta.can_migrate(self.connection) and
router.allow_migrate_model(self.connection.alias, model)):
queryset = model._default_manager.using(self.connection.alias).order_by(model._meta.pk.name)
for obj in queryset.iterator():
yield obj
yield from queryset.iterator()
# Serialize to a string
out = StringIO()
serializers.serialize("json", get_objects(), indent=None, stream=out)

View File

@ -28,8 +28,7 @@ class CursorWrapper:
def __iter__(self):
with self.db.wrap_database_errors:
for item in self.cursor:
yield item
yield from self.cursor
def __enter__(self):
return self

View File

@ -337,8 +337,7 @@ class BaseExpression:
yield self
for expr in self.get_source_expressions():
if expr:
for inner_expr in expr.flatten():
yield inner_expr
yield from expr.flatten()
class Expression(BaseExpression, Combinable):

View File

@ -742,8 +742,7 @@ class CallableChoiceIterator:
self.choices_func = choices_func
def __iter__(self):
for e in self.choices_func():
yield e
yield from self.choices_func()
class ChoiceField(Field):

View File

@ -539,14 +539,12 @@ class ChoiceWidget(Widget):
options from a BoundField for choice widgets.
"""
value = self.format_value(value)
for option in self.options(name, value, attrs):
yield option
yield from self.options(name, value, attrs)
def options(self, name, value, attrs=None):
"""Yield a flat list of options for this widgets."""
for group in self.optgroups(name, value, attrs):
for option in group[1]:
yield option
yield from group[1]
def optgroups(self, name, value, attrs=None):
"""Return a list of optgroups for this widget."""

View File

@ -162,8 +162,7 @@ class Template:
def __iter__(self):
for node in self.nodelist:
for subnode in node:
yield subnode
yield from node
def _render(self, context):
return self.nodelist.render(context)

View File

@ -43,8 +43,7 @@ class BaseContext:
return repr(self.dicts)
def __iter__(self):
for d in reversed(self.dicts):
yield d
yield from reversed(self.dicts)
def push(self, *args, **kwargs):
dicts = []
@ -192,8 +191,7 @@ class RenderContext(BaseContext):
template = None
def __iter__(self):
for d in self.dicts[-1]:
yield d
yield from self.dicts[-1]
def __contains__(self, key):
return key in self.dicts[-1]

View File

@ -148,10 +148,8 @@ class ForNode(Node):
reversed_text)
def __iter__(self):
for node in self.nodelist_loop:
yield node
for node in self.nodelist_empty:
yield node
yield from self.nodelist_loop
yield from self.nodelist_empty
def render(self, context):
if 'forloop' in context:
@ -297,8 +295,7 @@ class IfNode(Node):
def __iter__(self):
for _, nodelist in self.conditions_nodelists:
for node in nodelist:
yield node
yield from nodelist
@property
def nodelist(self):

View File

@ -63,8 +63,7 @@ class Loader(BaseLoader):
def get_template_sources(self, template_name):
for loader in self.loaders:
for origin in loader.get_template_sources(template_name):
yield origin
yield from loader.get_template_sources(template_name)
def cache_key(self, template_name, skip=None):
"""

View File

@ -83,8 +83,7 @@ class FakePayload:
def closing_iterator_wrapper(iterable, close):
try:
for item in iterable:
yield item
yield from iterable
finally:
request_finished.disconnect(close_old_connections)
close() # will fire request_finished

View File

@ -348,8 +348,7 @@ class Colour(models.Model):
name = models.CharField(max_length=50)
def __iter__(self):
for number in range(5):
yield number
yield from range(5)
def __str__(self):
return self.name

View File

@ -787,8 +787,7 @@ class Queries1Tests(TestCase):
n_obj = Note.objects.all()[0]
def g():
for i in [n_obj.pk]:
yield i
yield n_obj.pk
self.assertQuerysetEqual(Note.objects.filter(pk__in=f()), [])
self.assertEqual(list(Note.objects.filter(pk__in=g())), [n_obj])

View File

@ -103,9 +103,7 @@ class FunctionTests(SimpleTestCase):
)
def item_generator():
yield a
yield b
yield c
yield from (a, b, c)
self.assertEqual(
unordered_list(item_generator()),
@ -129,9 +127,7 @@ class FunctionTests(SimpleTestCase):
)
def item_generator():
yield a
yield b
yield c
yield from (a, b, c)
self.assertEqual(
unordered_list(item_generator(), autoescape=False),