-
Notifications
You must be signed in to change notification settings - Fork 589
Description
Opening this as a discussion topic.
Currently, when instantiating a Graph instance with a pass-in store instance, the store parameter must be either:
- An instance of something that is a subclass of
rdflib.store.Store, or - A string, to dereference a store implementation from a registered plugin
See:
Lines 325 to 329 in ab31c5e
| if not isinstance(store, Store): | |
| # TODO: error handling | |
| self.__store = store = plugin.get(store, Store)() | |
| else: | |
| self.__store = store |
However, I've twice encountered the situation where I want to pass in a store that looks like and acts like a rdflib.store.Store (via duck-typing) but does not inherit from rdflib.store.Store.
Eg, this doesn't work:
from nonrdflibmodule.store import MySpecialStore
from rdflib import Graph
mystore = MySpecialStore()
g = Graph(store=mystore) #<- failsThis situation, the Graph constructor sees that MySpecialStore does not inherit from rdflib.store.Store so it uses that as a lookup key to find a plugin, and fails because it is not a valid lookup key.
There is a workaround I've found, by temporarily registering the store:
from rdflib.plugin import register
register("tempstore", Store, "nonrdflibmodule.store", "MySpecialStore")
g = Graph(store="tempstore")
mystore = g.storeI know this is a niche situation, but I wonder if we could use some kind of duck-typing mechanism to check if a store implements a basic set of features, and allow it, even if it not a subclass of rdflib.store.Store.