From 806a80cef16ea08b5a33b4ae663b573e7f9a20c4 Mon Sep 17 00:00:00 2001 From: Victor Date: Thu, 14 Sep 2017 20:31:50 +0300 Subject: [PATCH] Fixes #1641 There's no need to explicitly raise StopIteration as that's what a bare return statement does for a generator function - so yes they're the same. As of late 2014 return is correct and raise StopIteration for ending a generator is on a depreciation schedule. See PEP 479 for full details. https://stackoverflow.com/q/14183803/248296 https://www.python.org/dev/peps/pep-0479/ --- mongoengine/queryset/queryset.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mongoengine/queryset/queryset.py b/mongoengine/queryset/queryset.py index cf913b01..60de19a2 100644 --- a/mongoengine/queryset/queryset.py +++ b/mongoengine/queryset/queryset.py @@ -92,7 +92,7 @@ class QuerySet(BaseQuerySet): # Raise StopIteration if we already established there were no more # docs in the db cursor. if not self._has_more: - raise StopIteration + return # Otherwise, populate more of the cache and repeat. if len(self._result_cache) <= pos: