]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Change generator termination from StopIteration to return.
authorpgjones <philip.graham.jones@googlemail.com>
Fri, 30 Oct 2015 20:20:58 +0000 (20:20 +0000)
committerpgjones <philip.graham.jones@googlemail.com>
Fri, 30 Oct 2015 20:20:58 +0000 (20:20 +0000)
From [PEP 479](https://www.python.org/dev/peps/pep-0479/) the correct way to
terminate a generator is to return (which implicitly raises StopIteration)
rather than raise StopIteration.

Without this change using sqlalchemy in python 3.5 or greater results in
these warnings
    PendingDeprecationWarning: generator '__iter__' raised StopIteration
which this commit should remove.

lib/sqlalchemy/engine/result.py
lib/sqlalchemy/ext/associationproxy.py

index 74a0fce771f96bce6abbb63610fd1128ed5403b5..7d1425c283dbc6bba2f7ef6e048921b1c0ced849 100644 (file)
@@ -712,7 +712,7 @@ class ResultProxy(object):
         while True:
             row = self.fetchone()
             if row is None:
-                raise StopIteration
+                return
             else:
                 yield row
 
index 29064ef27b2b84421a3f6e7b1626fb66938e07f9..31f16287df84779f832f432fe4785780909e5486 100644 (file)
@@ -603,7 +603,7 @@ class _AssociationList(_AssociationCollection):
 
         for member in self.col:
             yield self._get(member)
-        raise StopIteration
+        return
 
     def append(self, value):
         item = self._create(value)
@@ -907,7 +907,7 @@ class _AssociationSet(_AssociationCollection):
         """
         for member in self.col:
             yield self._get(member)
-        raise StopIteration
+        return
 
     def add(self, value):
         if value not in self: