From: pgjones Date: Fri, 30 Oct 2015 20:20:58 +0000 (+0000) Subject: Change generator termination from StopIteration to return. X-Git-Tag: rel_1_1_0b1~84^2~70^2~31^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6ab120558078bdcbfbe06d2ca55bd7a0d417bbb4;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Change generator termination from StopIteration to return. 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. --- diff --git a/lib/sqlalchemy/engine/result.py b/lib/sqlalchemy/engine/result.py index 74a0fce771..7d1425c283 100644 --- a/lib/sqlalchemy/engine/result.py +++ b/lib/sqlalchemy/engine/result.py @@ -712,7 +712,7 @@ class ResultProxy(object): while True: row = self.fetchone() if row is None: - raise StopIteration + return else: yield row diff --git a/lib/sqlalchemy/ext/associationproxy.py b/lib/sqlalchemy/ext/associationproxy.py index 29064ef27b..31f16287df 100644 --- a/lib/sqlalchemy/ext/associationproxy.py +++ b/lib/sqlalchemy/ext/associationproxy.py @@ -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: