From 4e7d59678e4d7cdd18b9aaec5da2aa00be7933ae Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Sat, 23 Sep 2017 00:26:36 +1200 Subject: [PATCH] python: Remove deprecated MSet.items and ESet.items --- xapian-bindings/python/pythontest.py | 29 ------------ xapian-bindings/python/smoketest.py | 6 +-- xapian-bindings/python/util.i | 88 ------------------------------------ xapian-core/docs/deprecation.rst | 7 +-- 4 files changed, 7 insertions(+), 123 deletions(-) diff --git a/xapian-bindings/python/pythontest.py b/xapian-bindings/python/pythontest.py index 301754826..c421e6f21 100644 --- a/xapian-bindings/python/pythontest.py +++ b/xapian-bindings/python/pythontest.py @@ -104,20 +104,6 @@ def test_mset_iter(): expect(items[2].collapse_count, 0) expect(items[2].document.get_data(), 'was it warm? three') - # Test coverage for mset.items - mset_items = mset.items - expect(len(mset), len(mset_items), "Expected number of items to be length of mset") - - context("testing mset_items[2]") - expect(mset_items[2][xapian.MSET_DID], 4) - expect(mset_items[2][xapian.MSET_WT] > 0.0, True) - expect(mset_items[2][xapian.MSET_RANK], 2) - expect(mset_items[2][xapian.MSET_PERCENT], 86) - # MSET_DOCUMENT is documented but not implemented! FIXME: resolve this - - # if it has never worked, we may just want to remove the documentation for - # it. - #expect(mset_items[2][xapian.MSET_DOCUMENT].get_data(), 'was it warm? three') - # Check iterators for sub-msets against the whole mset. for start in range(0, 6): for maxitems in range(0, 6): @@ -1613,21 +1599,6 @@ def test_compactor(): shutil.rmtree(tmpdir) -def test_leak_mset_items(): - """Test that items property of MSet doesn't leak - - """ - db = xapian.WritableDatabase('', xapian.DB_BACKEND_INMEMORY) - doc = xapian.Document() - doc.add_term('drip') - db.add_document(doc) - enq = xapian.Enquire(db) - enq.set_query(xapian.Query('drip')) - mset = enq.get_mset(0, 10) - - # Prior to 1.2.4 this next line leaked an object. - mset.items - def test_custom_matchspy(): class MSpy(xapian.MatchSpy): def __init__(self): diff --git a/xapian-bindings/python/smoketest.py b/xapian-bindings/python/smoketest.py index f9c444efa..ea9331a67 100644 --- a/xapian-bindings/python/smoketest.py +++ b/xapian-bindings/python/smoketest.py @@ -252,16 +252,16 @@ def test_all(): rset = xapian.RSet() rset.add_document(1) eset = enquire.get_eset(10, rset, xapian.Enquire.USE_EXACT_TERMFREQ, 1.0, testexpanddecider()) - eset_terms = [term[xapian.ESET_TNAME] for term in eset.items] + eset_terms = [item.term for item in eset] expect(len(eset_terms), eset.size(), "Unexpected number of terms returned by expand") if [t for t in eset_terms if t.startswith('a')]: raise TestFail("ExpandDecider was not used") # Check min_wt argument to get_eset() works (new in 1.2.5). eset = enquire.get_eset(100, rset, xapian.Enquire.USE_EXACT_TERMFREQ) - expect(eset.items[-1][xapian.ESET_WT] < 1.9, True, "test get_eset() without min_wt") + expect([i.weight for i in eset][-1] < 1.9, True, "test get_eset() without min_wt") eset = enquire.get_eset(100, rset, xapian.Enquire.USE_EXACT_TERMFREQ, 1.0, None, 1.9) - expect(eset.items[-1][xapian.ESET_WT] >= 1.9, True, "test get_eset() min_wt") + expect([i.weight for i in eset][-1] >= 1.9, True, "test get_eset() min_wt") # Check QueryParser parsing error. qp = xapian.QueryParser() diff --git a/xapian-bindings/python/util.i b/xapian-bindings/python/util.i index d96aeea8a..8b3d1f9fb 100644 --- a/xapian-bindings/python/util.i +++ b/xapian-bindings/python/util.i @@ -96,81 +96,6 @@ namespace Xapian { } %} -%typedef PyObject *LangSpecificListType; - -%inline %{ -#define MSET_DID 0 -#define MSET_WT 1 -#define MSET_RANK 2 -#define MSET_PERCENT 3 -#define MSET_DOCUMENT 4 - -#define ESET_TNAME 0 -#define ESET_WT 1 -%} - -%feature("nothread") Xapian::MSet::items; -%{ -/* The GIL must be held when this is called. */ -PyObject *Xapian_MSet_items_get(Xapian::MSet *mset) -{ - PyObject *retval = PyList_New(mset->size()); - if (retval == 0) { - return NULL; - } - - Py_ssize_t idx = 0; - for (Xapian::MSetIterator i = mset->begin(); i != mset->end(); ++i) { - PyObject *t = PyTuple_New(4); - if (!t) { - Py_DECREF(retval); - return NULL; - } - - PyList_SET_ITEM(retval, idx++, t); - - PyTuple_SET_ITEM(t, MSET_DID, PyInt_FromLong(*i)); - PyTuple_SET_ITEM(t, MSET_WT, PyFloat_FromDouble(i.get_weight())); - PyTuple_SET_ITEM(t, MSET_RANK, PyInt_FromLong(i.get_rank())); - PyTuple_SET_ITEM(t, MSET_PERCENT, PyInt_FromLong(i.get_percent())); - } - return retval; -} -%} - -%feature("nothread") Xapian::ESet::items; -%{ -/* The GIL must be held when this is called. */ -PyObject *Xapian_ESet_items_get(Xapian::ESet *eset) -{ - PyObject *retval = PyList_New(eset->size()); - if (retval == 0) { - return NULL; - } - - Py_ssize_t idx = 0; - for (Xapian::ESetIterator i = eset->begin(); i != eset->end(); ++i) { - PyObject *t = PyTuple_New(2); - if (!t) { - Py_DECREF(retval); - return NULL; - } - - PyList_SET_ITEM(retval, idx++, t); - - PyObject * str = PyString_FromStringAndSize((*i).data(), (*i).size()); - if (str == 0) { - Py_DECREF(retval); - return NULL; - } - - PyTuple_SET_ITEM(t, ESET_TNAME, str); - PyTuple_SET_ITEM(t, ESET_WT, PyFloat_FromDouble(i.get_weight())); - } - return retval; -} -%} - namespace Xapian { %extend TermIterator { bool __eq__(const TermIterator &other) { @@ -233,11 +158,6 @@ namespace Xapian { %rename(_ESetIterator) ESetIterator; %extend MSet { - %immutable; - // access to the items array - PyObject *items; - %mutable; - // for comparison int __cmp__(const MSet &other) { if (self->get_max_possible() != other.get_max_possible()) { @@ -258,14 +178,6 @@ namespace Xapian { return 0; } } - - //%apply LangSpecificListType items { PyObject *items } - - %extend ESet { - %immutable; - PyObject *items; - %mutable; - } } %fragment("XapianSWIG_anystring_as_ptr", "header", fragment="SWIG_AsPtr_std_string") { diff --git a/xapian-core/docs/deprecation.rst b/xapian-core/docs/deprecation.rst index 8aef6dcae..e7cbe8578 100644 --- a/xapian-core/docs/deprecation.rst +++ b/xapian-core/docs/deprecation.rst @@ -242,9 +242,6 @@ Bindings ========== ====== ======== ============================ ====================================================================== Deprecated Remove Language Feature name Upgrade suggestion and comments ========== ====== ======== ============================ ====================================================================== -1.2.5 1.5.0 Python MSet.items Iterate the MSet object itself instead. ----------- ------ -------- ---------------------------- ---------------------------------------------------------------------- -1.2.5 1.5.0 Python ESet.items Iterate the ESet object itself instead. ========== ====== ======== ============================ ====================================================================== Omega @@ -612,6 +609,10 @@ Removed Language Feature name Upgrade suggestion and comments 1.3.0 Python Non-pythonic iterators Use the pythonic iterators instead. ------- -------- ---------------------------- -------------------------------------------------------------------------------- 1.3.0 Python Stem_get_available_languages Use Stem.get_available_languages instead (static method instead of function) +------- -------- ---------------------------- -------------------------------------------------------------------------------- +1.5.0 Python MSet.items Iterate the MSet object itself instead. +------- -------- ---------------------------- -------------------------------------------------------------------------------- +1.5.0 Python ESet.items Iterate the ESet object itself instead. ======= ======== ============================ ================================================================================ .. [#rswg] This affects all SWIG generated bindings (currently: Python, PHP, Ruby, Tcl8 and CSharp) -- 2.11.4.GIT