Skip to content
Closed
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
2 changes: 1 addition & 1 deletion rdflib/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ def __init__(
identifier: Optional[Union[Node, str]] = None,
namespace_manager: Optional[NamespaceManager] = None,
base: Optional[str] = None,
bind_namespaces: str = "core"
bind_namespaces: Optional[str] = "core",
):
super(Graph, self).__init__()
self.base = base
Expand Down
10 changes: 6 additions & 4 deletions rdflib/namespace/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ class NamespaceManager(object):

"""

def __init__(self, graph: "Graph", bind_namespaces: str = "core"):
def __init__(self, graph: "Graph", bind_namespaces: Optional[str] = "core"):
self.graph = graph
self.__cache: Dict[str, Tuple[str, URIRef, str]] = {}
self.__cache_strict: Dict[str, Tuple[str, URIRef, str]] = {}
Expand All @@ -348,7 +348,9 @@ def __init__(self, graph: "Graph", bind_namespaces: str = "core"):

# bind Namespaces as per options.
# default is core
if bind_namespaces == "core":
if bind_namespaces is None:
pass # bind nothing
elif bind_namespaces == "core":
# bind a few core RDF namespaces
for prefix, ns in NAMESPACE_PREFIXES_CORE.items():
self.bind(prefix, ns)
Expand All @@ -365,8 +367,8 @@ def __init__(self, graph: "Graph", bind_namespaces: str = "core"):
# work out remainder - namespaces without prefixes
# only look those ones up
raise NotImplementedError("Haven't got to this option yet")
else: # bind_namespaces is None
pass # bind nothing
else:
raise ValueError(f"Invalid bind_namespaces value {bind_namespaces!r}")

def __contains__(self, ref: str) -> bool:
# checks if a reference is in any of the managed namespaces with syntax
Expand Down
14 changes: 14 additions & 0 deletions test/test_namespacemanager.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import sys
from pathlib import Path

import pytest

sys.path.append(str(Path(__file__).parent.parent.absolute()))
from rdflib import Graph
from rdflib.namespace import NAMESPACE_PREFIXES_CORE, NAMESPACE_PREFIXES_RDFLIB
Expand All @@ -24,3 +27,14 @@ def test_rdflib_prefixes_bound():

def test_cc_prefixes_bound():
pass


def test_no_prefixes_bound():
g = Graph(bind_namespaces=None)
assert len(list(g.namespaces())) == 0


def test_invalid_prefixes_bound():
with pytest.raises(ValueError):
g = Graph(bind_namespaces="INVALID")
list(g.namespaces())