Fix DeprecationWarning: generator '__iter__' raised StopIteration

Closes #498
This commit is contained in:
NotSqrt 2017-01-04 09:45:53 +01:00
parent 651f1b6c97
commit 9ffb61214c

View File

@ -106,6 +106,7 @@ class DictCursorBase(_cursor):
return res return res
def __iter__(self): def __iter__(self):
try:
if self._prefetch: if self._prefetch:
res = super(DictCursorBase, self).__iter__() res = super(DictCursorBase, self).__iter__()
first = res.next() first = res.next()
@ -118,6 +119,8 @@ class DictCursorBase(_cursor):
yield first yield first
while 1: while 1:
yield res.next() yield res.next()
except StopIteration:
return
class DictConnection(_connection): class DictConnection(_connection):
@ -343,6 +346,7 @@ class NamedTupleCursor(_cursor):
return map(nt._make, ts) return map(nt._make, ts)
def __iter__(self): def __iter__(self):
try:
it = super(NamedTupleCursor, self).__iter__() it = super(NamedTupleCursor, self).__iter__()
t = it.next() t = it.next()
@ -354,6 +358,8 @@ class NamedTupleCursor(_cursor):
while 1: while 1:
yield nt._make(it.next()) yield nt._make(it.next())
except StopIteration:
return
try: try:
from collections import namedtuple from collections import namedtuple