From 2a6cec2df4e5bc8bf4f1d3fc3cf573b78b7f9b25 Mon Sep 17 00:00:00 2001 From: Mads Jensen Date: Sun, 25 Feb 2018 10:51:14 +0100 Subject: [PATCH] Use yield from syntax introduced in Python 3.3. --- src/wiki/models/article.py | 9 +++------ src/wiki/plugins/macros/mdx/toc.py | 3 +-- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/wiki/models/article.py b/src/wiki/models/article.py index f5accc27..ebd5ea74 100644 --- a/src/wiki/models/article.py +++ b/src/wiki/models/article.py @@ -88,14 +88,12 @@ class Article(models.Model): def ancestor_objects(self): """NB! This generator is expensive, so use it with care!!""" for obj in self.articleforobject_set.filter(is_mptt=True): - for ancestor in obj.content_object.get_ancestors(): - yield ancestor + yield from obj.content_object.get_ancestors() def descendant_objects(self): """NB! This generator is expensive, so use it with care!!""" for obj in self.articleforobject_set.filter(is_mptt=True): - for descendant in obj.content_object.get_descendants(): - yield descendant + yield from obj.content_object.get_descendants() def get_children(self, max_num=None, user_can_read=None, **kwargs): """NB! This generator is expensive, so use it with care!!""" @@ -106,8 +104,7 @@ class Article(models.Model): **kwargs).can_read(user_can_read) else: objects = obj.content_object.get_children().filter(**kwargs) - for child in objects.order_by( - 'articles__article__current_revision__title'): + for child in objects.order_by('articles__article__current_revision__title'): cnt += 1 if max_num and cnt > max_num: return diff --git a/src/wiki/plugins/macros/mdx/toc.py b/src/wiki/plugins/macros/mdx/toc.py index 1eacbe2b..b36efdb1 100644 --- a/src/wiki/plugins/macros/mdx/toc.py +++ b/src/wiki/plugins/macros/mdx/toc.py @@ -49,8 +49,7 @@ def itertext(elem): if elem.text: yield elem.text for e in elem: - for s in itertext(e): - yield s + yield from itertext(e) if e.tail: yield e.tail -- 2.45.2