summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Car <nicholas.car@surroundaustralia.com>2020-12-27 21:07:24 +1000
committerGitHub <noreply@github.com>2020-12-27 21:07:24 +1000
commit74943a0a75dad2fee9974c868cd42e0ffd1b4aac (patch)
tree3cadbd282c1ef0838b2aaff23af2981dc4d776e4
parente5993334058b7a0e35d008d3e21b71eed88cf4c4 (diff)
parent2077524d43a103c3b9bf9fdd009a4942c7fff032 (diff)
downloadrdflib-74943a0a75dad2fee9974c868cd42e0ffd1b4aac.tar.gz
Merge pull request #1211 from edmondchuc/feat/sparql-result-serializer-docs
Add documentation and type hints for rdflib.query.Result and 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