diff --git a/rdflib/graph.py b/rdflib/graph.py index bc9ab05f2..90907cde0 100644 --- a/rdflib/graph.py +++ b/rdflib/graph.py @@ -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) @@ -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]] diff --git a/rdflib/plugins/parsers/nquads.py b/rdflib/plugins/parsers/nquads.py index 60b793b65..cadcfa28a 100644 --- a/rdflib/plugins/parsers/nquads.py +++ b/rdflib/plugins/parsers/nquads.py @@ -7,7 +7,7 @@ >>> g = ConjunctiveGraph() >>> data = open("test/data/nquads.rdflib/example.nquads", "rb") >>> g.parse(data, format="nquads") # doctest:+ELLIPSIS -)> +)> >>> assert len(g.store) == 449 >>> # There should be 16 separate contexts >>> assert len([x for x in g.store.contexts()]) == 16 diff --git a/test/test_dataset/test_dataset_add.py b/test/test_dataset/test_dataset_add.py index e2b587613..a3197ae2e 100644 --- a/test/test_dataset/test_dataset_add.py +++ b/test/test_dataset/test_dataset_add.py @@ -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(): @@ -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