diff options
author | Miel Vander Sande <miel.vandersande@meemoo.be> | 2022-08-04 22:16:10 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-04 22:16:10 +0200 |
commit | cc80c9c356e62596335bc8f1a81acb1016eaed74 (patch) | |
tree | 0b6a03a0a7218c8ed05de5888f2bfc753becdeec | |
parent | cfa418074b27b12aac905ba266b002a237c5ff4c (diff) | |
download | rdflib-cc80c9c356e62596335bc8f1a81acb1016eaed74.tar.gz |
fix: passing ConjunctiveGraph as namespace_manager (#2073)
pass the NamespaceManager of the ConjunctiveGraph as namespace_manager of the Graph created by the get_context() method instead of the ConjunctiveGraph object itself.
-rw-r--r-- | CHANGELOG.md | 16 | ||||
-rw-r--r-- | rdflib/graph.py | 3 | ||||
-rw-r--r-- | test/test_conjunctivegraph/test_conjunctive_graph.py | 12 |
3 files changed, 29 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a011613..d6163386 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,22 @@ CHANGE BARRIER is intended to reduce the potential for merge conflicts and will be removed for release. --> + <!-- --> + <!-- --> + <!-- CHANGE BARRIER: START --> + <!-- --> + <!-- --> + + - Fixes passing `NamespaceManager` in `ConjunctiveGraph`'s method `get_context()`. + The `get_context()` method will now pass the `NamespaceManager` of `ConjunctiveGraph` to the `namespace_manager` attribute of the newly created context graph, instead of the `ConjunctiveGraph` object itself. This cleans up an old FIXME commment. + [PR #2073](https://github.com/RDFLib/rdflib/pull/2073). + +<!-- --> +<!-- --> +<!-- CHANGE BARRIER: END --> +<!-- --> +<!-- --> + <!-- --> <!-- --> <!-- CHANGE BARRIER: START --> diff --git a/rdflib/graph.py b/rdflib/graph.py index d2713aea..7dc69dad 100644 --- a/rdflib/graph.py +++ b/rdflib/graph.py @@ -1915,9 +1915,8 @@ class ConjunctiveGraph(Graph): identifier must be a URIRef or BNode. """ - # TODO: FIXME - why is ConjunctiveGraph passed as namespace_manager? return Graph( - store=self.store, identifier=identifier, namespace_manager=self, base=base # type: ignore[arg-type] + store=self.store, identifier=identifier, namespace_manager=self.namespace_manager, base=base # type: ignore[arg-type] ) def remove_context(self, context): diff --git a/test/test_conjunctivegraph/test_conjunctive_graph.py b/test/test_conjunctivegraph/test_conjunctive_graph.py index d6802f3f..f26cb77e 100644 --- a/test/test_conjunctivegraph/test_conjunctive_graph.py +++ b/test/test_conjunctivegraph/test_conjunctive_graph.py @@ -6,6 +6,7 @@ Tests for ConjunctiveGraph that do not depend on the underlying store import pytest from rdflib import ConjunctiveGraph, Graph +from rdflib.namespace import NamespaceManager from rdflib.parser import StringInputSource from rdflib.term import BNode, Identifier, URIRef @@ -47,6 +48,17 @@ def test_quad_contexts(): assert isinstance(q[3], Graph) +def test_context_namespaces(): + cg = ConjunctiveGraph() + a = URIRef("urn:a") + ns = URIRef("http://example.org/") + cg.bind("ex", ns) + g = cg.get_context(a) + + assert type(g.namespace_manager) is NamespaceManager + assert ("ex", ns) in g.namespace_manager.namespaces() + + def get_graph_ids_tests(): def check(kws): cg = ConjunctiveGraph() |