Skip to content

Commit ab31c5e

Browse files
authored
Make Store.namespaces an empty generator (#1432)
Fixes #1431
1 parent 93ea6e4 commit ab31c5e

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

rdflib/store.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,11 @@ def namespace(self, prefix):
364364

365365
def namespaces(self):
366366
""" """
367+
# This is here so that the function becomes an empty generator.
368+
# See https://stackoverflow.com/q/13243766 and
369+
# https://www.python.org/dev/peps/pep-0255/#why-a-new-keyword-for-yield-why-not-a-builtin-function-instead
370+
if False:
371+
yield None # type: ignore[unreachable]
367372

368373
# Optional Transactional methods
369374

test/test_store.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import unittest
2+
from rdflib import Graph
3+
from rdflib.store import Store
4+
from rdflib.namespace import NamespaceManager
5+
6+
7+
class TestAbstractStore(unittest.TestCase):
8+
def test_namespaces(self):
9+
"""
10+
This tests that Store.namespaces is an empty generator.
11+
"""
12+
store = Store()
13+
self.assertEqual(list(store.namespaces()), [])
14+
15+
def test_namespaces_via_manager(self):
16+
"""
17+
This tests that NamespaceManager.namespaces works correctly with an
18+
abstract Store.
19+
"""
20+
namespace_manager = NamespaceManager(Graph(store=Store()))
21+
self.assertEqual(list(namespace_manager.namespaces()), [])
22+
23+
24+
if __name__ == "__main__":
25+
unittest.main()

0 commit comments

Comments
 (0)