diff --git a/python/README.md b/python/README.md index 8996f170..25c9de96 100644 --- a/python/README.md +++ b/python/README.md @@ -187,16 +187,14 @@ assert store.query('ASK { ?s ?s ?s }') The `SELECT` queries return an iterator of query solutions that could be indexed by variable name or position in the `SELECT` clause: ```python -solutions = list(store.query('SELECT ?s WHERE { ?s ?p ?o }')) -assert solutions[0][0] == s -assert solutions[0]['s'] == s +for solution in store.query('SELECT ?s WHERE { ?s ?p ?o }'): + assert solution[0] == solution['s'] ``` -The `CONSTRUCT` and `DESCRIBE` queries return an iterator of query solutions that could be indexed by variable name or position in the `SELECT` clause: +The `CONSTRUCT` and `DESCRIBE` queries return an iterator of triples: ```python -solutions = list(store.query('SELECT ?s WHERE { ?s ?p ?o }')) -assert solutions[0][0] == s -assert solutions[0]['s'] == s +for (s, p, o) in store.query('CONSTRUCT { ?s ?p ?o } WHERE { ?s ?p ?o }'): + print(s) ``` ### `load` diff --git a/python/src/store_utils.rs b/python/src/store_utils.rs index f4520cfe..4fed0a4a 100644 --- a/python/src/store_utils.rs +++ b/python/src/store_utils.rs @@ -4,7 +4,8 @@ use oxigraph::sparql::{QueryResult, QuerySolution}; use oxigraph::Result; use pyo3::exceptions::TypeError; use pyo3::prelude::*; -use pyo3::{create_exception, PyIterProtocol, PyMappingProtocol, PyNativeType}; +use pyo3::{create_exception, PyIterProtocol, PyMappingProtocol, PyNativeType, PyObjectProtocol}; +use std::fmt::Write; use std::vec::IntoIter; create_exception!(oxigraph, ParseError, pyo3::exceptions::Exception); @@ -77,6 +78,18 @@ pub struct PyQuerySolution { inner: QuerySolution, } +#[pyproto] +impl PyObjectProtocol for PyQuerySolution { + fn __repr__(&self) -> String { + let mut buffer = "'); + buffer + } +} + #[pyproto] impl PyMappingProtocol for PyQuerySolution { fn __len__(&self) -> usize { diff --git a/python/tests/test_store.py b/python/tests/test_store.py index 5901a628..8baa0202 100644 --- a/python/tests/test_store.py +++ b/python/tests/test_store.py @@ -66,8 +66,7 @@ class TestAbstractStore(unittest.TestCase, ABC): [(foo, bar, baz, DefaultGraph()), (foo, bar, baz, graph)], ) self.assertEqual( - list(store.match(None, None, None, graph)), - [(foo, bar, baz, graph)], + list(store.match(None, None, None, graph)), [(foo, bar, baz, graph)], ) self.assertEqual( list(store.match(foo, None, None, DefaultGraph())),