Refs #23919 -- Used yield from.
This commit is contained in:
parent
4cffa9a1ff
commit
3dcc351691
|
@ -312,8 +312,7 @@ class ListMixin:
|
||||||
def newItems():
|
def newItems():
|
||||||
for i in range(origLen + 1):
|
for i in range(origLen + 1):
|
||||||
if i == start:
|
if i == start:
|
||||||
for val in valueList:
|
yield from valueList
|
||||||
yield val
|
|
||||||
|
|
||||||
if i < origLen:
|
if i < origLen:
|
||||||
if i < start or i >= stop:
|
if i < start or i >= stop:
|
||||||
|
|
|
@ -402,9 +402,7 @@ class ManifestFilesMixin(HashedFilesMixin):
|
||||||
|
|
||||||
def post_process(self, *args, **kwargs):
|
def post_process(self, *args, **kwargs):
|
||||||
self.hashed_files = OrderedDict()
|
self.hashed_files = OrderedDict()
|
||||||
all_post_processed = super().post_process(*args, **kwargs)
|
yield from super().post_process(*args, **kwargs)
|
||||||
for post_processed in all_post_processed:
|
|
||||||
yield post_processed
|
|
||||||
self.save_manifest()
|
self.save_manifest()
|
||||||
|
|
||||||
def save_manifest(self):
|
def save_manifest(self):
|
||||||
|
|
|
@ -37,8 +37,7 @@ def get_files(storage, ignore_patterns=None, location=''):
|
||||||
continue
|
continue
|
||||||
if location:
|
if location:
|
||||||
dir = os.path.join(location, dir)
|
dir = os.path.join(location, dir)
|
||||||
for fn in get_files(storage, ignore_patterns, dir):
|
yield from get_files(storage, ignore_patterns, dir)
|
||||||
yield fn
|
|
||||||
|
|
||||||
|
|
||||||
def check_settings(base_url=None):
|
def check_settings(base_url=None):
|
||||||
|
|
|
@ -166,8 +166,7 @@ class Command(BaseCommand):
|
||||||
if count_only:
|
if count_only:
|
||||||
yield queryset.order_by().count()
|
yield queryset.order_by().count()
|
||||||
else:
|
else:
|
||||||
for obj in queryset.iterator():
|
yield from queryset.iterator()
|
||||||
yield obj
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.stdout.ending = None
|
self.stdout.ending = None
|
||||||
|
|
|
@ -69,8 +69,7 @@ def Deserializer(stream_or_string, **options):
|
||||||
stream_or_string = stream_or_string.decode()
|
stream_or_string = stream_or_string.decode()
|
||||||
try:
|
try:
|
||||||
objects = json.loads(stream_or_string)
|
objects = json.loads(stream_or_string)
|
||||||
for obj in PythonDeserializer(objects, **options):
|
yield from PythonDeserializer(objects, **options)
|
||||||
yield obj
|
|
||||||
except (GeneratorExit, DeserializationError):
|
except (GeneratorExit, DeserializationError):
|
||||||
raise
|
raise
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
|
|
|
@ -70,8 +70,7 @@ def Deserializer(stream_or_string, **options):
|
||||||
else:
|
else:
|
||||||
stream = stream_or_string
|
stream = stream_or_string
|
||||||
try:
|
try:
|
||||||
for obj in PythonDeserializer(yaml.load(stream, Loader=SafeLoader), **options):
|
yield from PythonDeserializer(yaml.load(stream, Loader=SafeLoader), **options)
|
||||||
yield obj
|
|
||||||
except (GeneratorExit, DeserializationError):
|
except (GeneratorExit, DeserializationError):
|
||||||
raise
|
raise
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
|
|
|
@ -113,8 +113,7 @@ class BaseDatabaseCreation:
|
||||||
if (model._meta.can_migrate(self.connection) and
|
if (model._meta.can_migrate(self.connection) and
|
||||||
router.allow_migrate_model(self.connection.alias, model)):
|
router.allow_migrate_model(self.connection.alias, model)):
|
||||||
queryset = model._default_manager.using(self.connection.alias).order_by(model._meta.pk.name)
|
queryset = model._default_manager.using(self.connection.alias).order_by(model._meta.pk.name)
|
||||||
for obj in queryset.iterator():
|
yield from queryset.iterator()
|
||||||
yield obj
|
|
||||||
# Serialize to a string
|
# Serialize to a string
|
||||||
out = StringIO()
|
out = StringIO()
|
||||||
serializers.serialize("json", get_objects(), indent=None, stream=out)
|
serializers.serialize("json", get_objects(), indent=None, stream=out)
|
||||||
|
|
|
@ -28,8 +28,7 @@ class CursorWrapper:
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
with self.db.wrap_database_errors:
|
with self.db.wrap_database_errors:
|
||||||
for item in self.cursor:
|
yield from self.cursor
|
||||||
yield item
|
|
||||||
|
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
return self
|
return self
|
||||||
|
|
|
@ -337,8 +337,7 @@ class BaseExpression:
|
||||||
yield self
|
yield self
|
||||||
for expr in self.get_source_expressions():
|
for expr in self.get_source_expressions():
|
||||||
if expr:
|
if expr:
|
||||||
for inner_expr in expr.flatten():
|
yield from expr.flatten()
|
||||||
yield inner_expr
|
|
||||||
|
|
||||||
|
|
||||||
class Expression(BaseExpression, Combinable):
|
class Expression(BaseExpression, Combinable):
|
||||||
|
|
|
@ -742,8 +742,7 @@ class CallableChoiceIterator:
|
||||||
self.choices_func = choices_func
|
self.choices_func = choices_func
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
for e in self.choices_func():
|
yield from self.choices_func()
|
||||||
yield e
|
|
||||||
|
|
||||||
|
|
||||||
class ChoiceField(Field):
|
class ChoiceField(Field):
|
||||||
|
|
|
@ -539,14 +539,12 @@ class ChoiceWidget(Widget):
|
||||||
options from a BoundField for choice widgets.
|
options from a BoundField for choice widgets.
|
||||||
"""
|
"""
|
||||||
value = self.format_value(value)
|
value = self.format_value(value)
|
||||||
for option in self.options(name, value, attrs):
|
yield from self.options(name, value, attrs)
|
||||||
yield option
|
|
||||||
|
|
||||||
def options(self, name, value, attrs=None):
|
def options(self, name, value, attrs=None):
|
||||||
"""Yield a flat list of options for this widgets."""
|
"""Yield a flat list of options for this widgets."""
|
||||||
for group in self.optgroups(name, value, attrs):
|
for group in self.optgroups(name, value, attrs):
|
||||||
for option in group[1]:
|
yield from group[1]
|
||||||
yield option
|
|
||||||
|
|
||||||
def optgroups(self, name, value, attrs=None):
|
def optgroups(self, name, value, attrs=None):
|
||||||
"""Return a list of optgroups for this widget."""
|
"""Return a list of optgroups for this widget."""
|
||||||
|
|
|
@ -162,8 +162,7 @@ class Template:
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
for node in self.nodelist:
|
for node in self.nodelist:
|
||||||
for subnode in node:
|
yield from node
|
||||||
yield subnode
|
|
||||||
|
|
||||||
def _render(self, context):
|
def _render(self, context):
|
||||||
return self.nodelist.render(context)
|
return self.nodelist.render(context)
|
||||||
|
|
|
@ -43,8 +43,7 @@ class BaseContext:
|
||||||
return repr(self.dicts)
|
return repr(self.dicts)
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
for d in reversed(self.dicts):
|
yield from reversed(self.dicts)
|
||||||
yield d
|
|
||||||
|
|
||||||
def push(self, *args, **kwargs):
|
def push(self, *args, **kwargs):
|
||||||
dicts = []
|
dicts = []
|
||||||
|
@ -192,8 +191,7 @@ class RenderContext(BaseContext):
|
||||||
template = None
|
template = None
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
for d in self.dicts[-1]:
|
yield from self.dicts[-1]
|
||||||
yield d
|
|
||||||
|
|
||||||
def __contains__(self, key):
|
def __contains__(self, key):
|
||||||
return key in self.dicts[-1]
|
return key in self.dicts[-1]
|
||||||
|
|
|
@ -148,10 +148,8 @@ class ForNode(Node):
|
||||||
reversed_text)
|
reversed_text)
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
for node in self.nodelist_loop:
|
yield from self.nodelist_loop
|
||||||
yield node
|
yield from self.nodelist_empty
|
||||||
for node in self.nodelist_empty:
|
|
||||||
yield node
|
|
||||||
|
|
||||||
def render(self, context):
|
def render(self, context):
|
||||||
if 'forloop' in context:
|
if 'forloop' in context:
|
||||||
|
@ -297,8 +295,7 @@ class IfNode(Node):
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
for _, nodelist in self.conditions_nodelists:
|
for _, nodelist in self.conditions_nodelists:
|
||||||
for node in nodelist:
|
yield from nodelist
|
||||||
yield node
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def nodelist(self):
|
def nodelist(self):
|
||||||
|
|
|
@ -63,8 +63,7 @@ class Loader(BaseLoader):
|
||||||
|
|
||||||
def get_template_sources(self, template_name):
|
def get_template_sources(self, template_name):
|
||||||
for loader in self.loaders:
|
for loader in self.loaders:
|
||||||
for origin in loader.get_template_sources(template_name):
|
yield from loader.get_template_sources(template_name)
|
||||||
yield origin
|
|
||||||
|
|
||||||
def cache_key(self, template_name, skip=None):
|
def cache_key(self, template_name, skip=None):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -83,8 +83,7 @@ class FakePayload:
|
||||||
|
|
||||||
def closing_iterator_wrapper(iterable, close):
|
def closing_iterator_wrapper(iterable, close):
|
||||||
try:
|
try:
|
||||||
for item in iterable:
|
yield from iterable
|
||||||
yield item
|
|
||||||
finally:
|
finally:
|
||||||
request_finished.disconnect(close_old_connections)
|
request_finished.disconnect(close_old_connections)
|
||||||
close() # will fire request_finished
|
close() # will fire request_finished
|
||||||
|
|
|
@ -348,8 +348,7 @@ class Colour(models.Model):
|
||||||
name = models.CharField(max_length=50)
|
name = models.CharField(max_length=50)
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
for number in range(5):
|
yield from range(5)
|
||||||
yield number
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
|
@ -787,8 +787,7 @@ class Queries1Tests(TestCase):
|
||||||
n_obj = Note.objects.all()[0]
|
n_obj = Note.objects.all()[0]
|
||||||
|
|
||||||
def g():
|
def g():
|
||||||
for i in [n_obj.pk]:
|
yield n_obj.pk
|
||||||
yield i
|
|
||||||
self.assertQuerysetEqual(Note.objects.filter(pk__in=f()), [])
|
self.assertQuerysetEqual(Note.objects.filter(pk__in=f()), [])
|
||||||
self.assertEqual(list(Note.objects.filter(pk__in=g())), [n_obj])
|
self.assertEqual(list(Note.objects.filter(pk__in=g())), [n_obj])
|
||||||
|
|
||||||
|
|
|
@ -103,9 +103,7 @@ class FunctionTests(SimpleTestCase):
|
||||||
)
|
)
|
||||||
|
|
||||||
def item_generator():
|
def item_generator():
|
||||||
yield a
|
yield from (a, b, c)
|
||||||
yield b
|
|
||||||
yield c
|
|
||||||
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
unordered_list(item_generator()),
|
unordered_list(item_generator()),
|
||||||
|
@ -129,9 +127,7 @@ class FunctionTests(SimpleTestCase):
|
||||||
)
|
)
|
||||||
|
|
||||||
def item_generator():
|
def item_generator():
|
||||||
yield a
|
yield from (a, b, c)
|
||||||
yield b
|
|
||||||
yield c
|
|
||||||
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
unordered_list(item_generator(), autoescape=False),
|
unordered_list(item_generator(), autoescape=False),
|
||||||
|
|
Loading…
Reference in New Issue