Skip to content

Commit a7c7ebe

Browse files
authored
Merge pull request #866 from joernhees/enh827
ClosedNamespace returns right exception for way of access, enhances #827
2 parents b0e5595 + bbe233c commit a7c7ebe

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

rdflib/namespace.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def __init__(self, uri, terms):
169169
def term(self, name):
170170
uri = self.__uris.get(name)
171171
if uri is None:
172-
raise AttributeError(
172+
raise KeyError(
173173
"term '{}' not in namespace '{}'".format(name, self.uri)
174174
)
175175
else:
@@ -182,7 +182,10 @@ def __getattr__(self, name):
182182
if name.startswith("__"): # ignore any special Python names!
183183
raise AttributeError
184184
else:
185-
return self.term(name)
185+
try:
186+
return self.term(name)
187+
except KeyError as e:
188+
raise AttributeError(e)
186189

187190
def __str__(self):
188191
return text_type(self.uri)

0 commit comments

Comments
 (0)