Skip to content

Commit 58c45d6

Browse files
committed
fixed SPARQL evaluate issue with StopIteration in py3.7
1 parent 9516ac5 commit 58c45d6

File tree

2 files changed

+5
-16
lines changed

2 files changed

+5
-16
lines changed

rdflib/plugins/sparql/evaluate.py

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"""
1616

1717
import collections
18+
import itertools
1819

1920
from rdflib import Variable, Graph, BNode, URIRef, Literal
2021
from six import iteritems, itervalues
@@ -321,22 +322,9 @@ def evalOrderBy(ctx, part):
321322

322323

323324
def evalSlice(ctx, slice):
324-
# import pdb; pdb.set_trace()
325325
res = evalPart(ctx, slice.p)
326-
i = 0
327-
while i < slice.start:
328-
next(res)
329-
i += 1
330-
i = 0
331-
for x in res:
332-
i += 1
333-
if slice.length is None:
334-
yield x
335-
else:
336-
if i <= slice.length:
337-
yield x
338-
else:
339-
break
326+
327+
return itertools.islice(res, slice.start, slice.start+slice.length if slice.length is not None else None)
340328

341329

342330
def evalReduced(ctx, part):

rdflib/query.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from __future__ import print_function
44

55
import os
6+
import itertools
67
import shutil
78
import tempfile
89
import warnings
@@ -185,7 +186,7 @@ def _get_bindings(self):
185186
return self._bindings
186187

187188
def _set_bindings(self, b):
188-
if isinstance(b, types.GeneratorType):
189+
if isinstance(b, (types.GeneratorType, itertools.islice)):
189190
self._genbindings = b
190191
self._bindings = []
191192
else:

0 commit comments

Comments
 (0)