Skip to content

Commit

Permalink
Fix StopIteration error on Python 3.7, and fix other deprecations.
Browse files Browse the repository at this point in the history
  • Loading branch information
jamadden committed Oct 5, 2018
1 parent 169bb9f commit 8b6cadb
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 12 deletions.
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

- Drop support for Python 3.3.

- Add support for Python 3.7. ``SortingIndexMixin.sort`` now just
returns instead of raising ``StopIteration`` as required by
:pep:`479`. See `issue 20 <https://github.com/zopefoundation/zope.index/pull/20>`_.

- Docs are now hosted at https://zopeindex.readthedocs.io/

- Drop support for ``setup.py test``.
Expand Down
9 changes: 6 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ def read(*rnames):
with open(os.path.join(os.path.dirname(__file__), *rnames)) as f:
return f.read()

long_description = (open('README.rst').read() +
'\n\n' +
open('CHANGES.rst').read())
long_description = (
read('README.rst')
+ '\n\n'
+ read('CHANGES.rst')
)

class optional_build_ext(build_ext):
"""This class subclasses build_ext and allows
Expand Down Expand Up @@ -85,6 +87,7 @@ def _unavailable(self, e):
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
'Natural Language :: English',
Expand Down
10 changes: 5 additions & 5 deletions src/zope/index/field/sorting.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ def sort(self, docids, reverse=False, limit=None):

numdocs = getattr(self, self._sorting_num_docs_attr).value
if not numdocs:
raise StopIteration
return

if not isinstance(docids,
(self.family.IF.Set, self.family.IF.TreeSet)):
docids = self.family.IF.Set(docids)
if not docids:
raise StopIteration
return

rlen = len(docids)

Expand Down Expand Up @@ -88,7 +88,7 @@ def nsort():
it = iter(iterable)
result = sorted(islice(it, 0, limit))
if not result:
raise StopIteration
return
insort = bisect.insort
pop = result.pop
los = result[-1] # los --> Largest of the nsmallest
Expand Down Expand Up @@ -118,7 +118,7 @@ def nsort():
n += 1
yield docid
if limit and n >= limit:
raise StopIteration
return
else:
# If the result set is not much larger than the number
# of documents in this index, or if we need to sort in
Expand All @@ -129,4 +129,4 @@ def nsort():
n += 1
yield docid
if limit and n >= limit:
raise StopIteration
return
4 changes: 2 additions & 2 deletions src/zope/index/field/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,8 @@ def test_insert_none_value_to_update_does_not_raise_typeerror(self):
def test_insert_none_value_does_insert_into_forward_index(self):
index = self._makeOne()
index.index_doc(1, None)
self.assertEquals(len(index._fwd_index), 1)
self.assertEquals(len(index._rev_index), 1)
self.assertEqual(len(index._fwd_index), 1)
self.assertEqual(len(index._rev_index), 1)

def test_suite():
return unittest.TestSuite((
Expand Down
5 changes: 4 additions & 1 deletion src/zope/index/text/ricecode.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ def __init__(self, buf=None):
self.bitsleft = 0

def tostring(self):
return self.bytes.tostring()
# tostring is deprecated on Python 3, but tobytes isn't available
# on Python 2
tobytes = getattr(self.bytes, 'tobytes', None) or self.bytes.tostring
return tobytes()

def __getitem__(self, i):
byte, offset = divmod(i, 8)
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tox]
envlist =
py27,py34,py35,py36,pypy,pypy3,coverage,docs
py27,py34,py35,py36,py37,pypy,pypy3,coverage,docs

[testenv]
commands =
Expand Down

0 comments on commit 8b6cadb

Please sign in to comment.