Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions rdflib/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -2346,8 +2346,7 @@ def parse(

context = self.default_context
context.parse(source, publicID=publicID, format=format, **args)
# TODO: FIXME: This should not return context, but self.
return context
return self

def __reduce__(self) -> Tuple[Type[Graph], Tuple[Store, _ContextIdentifierType]]:
return ConjunctiveGraph, (self.store, self.identifier)
Expand Down Expand Up @@ -2615,11 +2614,10 @@ def parse(
(i.e. :attr:`.Dataset.default_context`).
"""

c = ConjunctiveGraph.parse(
ConjunctiveGraph.parse(
self, source, publicID, format, location, file, data, **args
)
self.graph(c)
return c
return self

def add_graph(
self, g: Optional[Union[_ContextIdentifierType, _ContextType, str]]
Expand Down
2 changes: 1 addition & 1 deletion rdflib/plugins/parsers/nquads.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
>>> g = ConjunctiveGraph()
>>> data = open("test/data/nquads.rdflib/example.nquads", "rb")
>>> g.parse(data, format="nquads") # doctest:+ELLIPSIS
<Graph identifier=... (<class 'rdflib.graph.Graph'>)>
<Graph identifier=... (<class 'rdflib.graph.ConjunctiveGraph'>)>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The doctest is updated to the correct class type now that ConjunctiveGraph's parse method returns Self.

>>> assert len(g.store) == 449
>>> # There should be 16 separate contexts
>>> assert len([x for x in g.store.contexts()]) == 16
Expand Down
13 changes: 13 additions & 0 deletions test/test_dataset/test_dataset_add.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from rdflib import RDF, RDFS, Dataset, Graph, URIRef
from test.data import TEST_DATA_DIR


def test_behaviour_where_graph_is_created_via_dataset():
Expand Down Expand Up @@ -86,3 +87,15 @@ def test_adding_appends_to_dataset_graph():
graph = ds.add_graph(another_graph)
assert len(graph) == 3
assert len(ds) == 3


def test_dataset_parse_return_value():
"""
Test that the return value of ds.parse has the same reference as ds.
"""
ds = Dataset()
return_value = ds.parse(
source=TEST_DATA_DIR / "nquads.rdflib/example.nquads", format="nquads"
)
assert len(ds)
assert return_value is ds
Loading