summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdmond Chuc <edmond.chuc@outlook.com>2020-12-08 22:34:28 +1000
committerEdmond Chuc <edmond.chuc@outlook.com>2020-12-08 22:35:05 +1000
commit2077524d43a103c3b9bf9fdd009a4942c7fff032 (patch)
treeb9276de2582f122269597420c04f9648bfc614e3
parentc5ff12717c02cf21abc8dd00ed8f0ec27071ba5d (diff)
downloadrdflib-2077524d43a103c3b9bf9fdd009a4942c7fff032.tar.gz
Add documentation and type hints for rdflib.query.Result. Update documentation and type hints for rdflib.graph.Graph.
-rw-r--r--rdflib/graph.py10
-rw-r--r--rdflib/query.py26
2 files changed, 29 insertions, 7 deletions
diff --git a/rdflib/graph.py b/rdflib/graph.py
index e0d5f854..efc0e712 100644
--- a/rdflib/graph.py
+++ b/rdflib/graph.py
@@ -1130,13 +1130,13 @@ class Graph(Node):
def query(
self,
query_object,
- processor="sparql",
- result="sparql",
+ processor: str = "sparql",
+ result: str = "sparql",
initNs=None,
initBindings=None,
- use_store_provided=True,
+ use_store_provided: bool = True,
**kwargs
- ):
+ ) -> query.Result:
"""
Query this graph.
@@ -1147,7 +1147,7 @@ class Graph(Node):
if none are given, the namespaces from the graph's namespace manager
are used.
- :returntype: rdflib.query.QueryResult
+ :returntype: rdflib.query.Result
"""
diff --git a/rdflib/query.py b/rdflib/query.py
index ae23e3b3..c67f15ea 100644
--- a/rdflib/query.py
+++ b/rdflib/query.py
@@ -4,6 +4,7 @@ import shutil
import tempfile
import warnings
import types
+from typing import Optional
from io import BytesIO
@@ -205,8 +206,29 @@ class Result(object):
return parser.parse(source, content_type=content_type, **kwargs)
- def serialize(self, destination=None, encoding="utf-8", format="xml", **args):
-
+ def serialize(
+ self,
+ destination: Optional[str] = None,
+ encoding: str = "utf-8",
+ format: str = "xml",
+ **args,
+ ) -> Optional[bytes]:
+ """
+ Serialize the query result.
+
+ The :code:`format` argument determines the Serializer class to use.
+
+ - csv: :class:`~rdflib.plugins.sparql.results.csvresults.CSVResultSerializer`
+ - json: :class:`~rdflib.plugins.sparql.results.jsonresults.JSONResultSerializer`
+ - txt: :class:`~rdflib.plugins.sparql.results.txtresults.TXTResultSerializer`
+ - xml: :class:`~rdflib.plugins.sparql.results.xmlresults.XMLResultSerializer`
+
+ :param destination: Path of file output.
+ :param encoding: Encoding of output.
+ :param format: One of ['csv', 'json', 'txt', xml']
+ :param args:
+ :return: bytes
+ """
if self.type in ("CONSTRUCT", "DESCRIBE"):
return self.graph.serialize(
destination, encoding=encoding, format=format, **args