Skip to content

Commit 8971426

Browse files
committed
Adjust the type hint for Graph open to reflect a SPARQLUpdateStore configuration
Also adjust the type hint for ReadOnlyGraphAggregate and for further stores
1 parent 4a819fa commit 8971426

File tree

5 files changed

+22
-10
lines changed

5 files changed

+22
-10
lines changed

rdflib/graph.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,9 @@ def rollback(self: _GraphT) -> _GraphT:
607607
self.__store.rollback()
608608
return self
609609

610-
def open(self, configuration: str, create: bool = False) -> int | None:
610+
def open(
611+
self, configuration: str | tuple[str, str], create: bool = False
612+
) -> int | None:
611613
"""Open the graph store
612614
613615
Might be necessary for stores that require opening a connection to a
@@ -3027,7 +3029,7 @@ def commit(self) -> NoReturn:
30273029
def rollback(self) -> NoReturn:
30283030
raise ModificationException()
30293031

3030-
def open(self, configuration: str, create: bool = False) -> None:
3032+
def open(self, configuration: str | tuple[str, str], create: bool = False) -> None:
30313033
# TODO: is there a use case for this method?
30323034
for graph in self.graphs:
30333035
# type error: Too many arguments for "open" of "Graph"

rdflib/plugins/stores/auditable.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ def __init__(self, store: Store):
6565
] = []
6666
self.rollbackLock = threading.RLock()
6767

68-
def open(self, configuration: str, create: bool = True) -> int | None:
68+
def open(
69+
self, configuration: str | tuple[str, str], create: bool = True
70+
) -> int | None:
6971
return self.store.open(configuration, create)
7072

7173
def close(self, commit_pending_transaction: bool = False) -> None:

rdflib/plugins/stores/berkeleydb.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,16 @@ def _init_db_environment(
126126
def is_open(self) -> bool:
127127
return self.__open
128128

129-
def open(self, path: str, create: bool = True) -> int | None:
129+
def open(
130+
self, configuration: str | tuple[str, str], create: bool = True
131+
) -> int | None:
130132
if not has_bsddb:
131133
return NO_STORE
132-
homeDir = path # noqa: N806
134+
135+
if type(configuration) is str:
136+
homeDir = configuration # noqa: N806
137+
else:
138+
raise Exception("Invalid configuration provided")
133139

134140
if self.__identifier is None:
135141
self.__identifier = URIRef(pathname2url(abspath(homeDir)))

rdflib/plugins/stores/sparqlstore.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,11 @@ def __init__(
184184
self._queries = 0
185185

186186
# type error: Missing return statement
187-
def open(self, configuration: str, create: bool = False) -> int | None: # type: ignore[return]
187+
def open(self, configuration: str | tuple[str, str], create: bool = False) -> int | None: # type: ignore[return]
188188
"""This method is included so that calls to this Store via Graph, e.g. Graph("SPARQLStore"),
189189
can set the required parameters
190190
"""
191-
if type(configuration) == str: # noqa: E721
191+
if type(configuration) is str:
192192
self.query_endpoint = configuration
193193
else:
194194
raise Exception(

rdflib/store.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,13 @@ def node_pickler(self) -> NodePickler:
184184
def create(self, configuration: str) -> None:
185185
self.dispatcher.dispatch(StoreCreatedEvent(configuration=configuration))
186186

187-
def open(self, configuration: str, create: bool = False) -> int | None:
188-
"""Opens the store specified by the configuration string.
187+
def open(
188+
self, configuration: str | tuple[str, str], create: bool = False
189+
) -> int | None:
190+
"""Opens the store specified by the configuration.
189191
190192
Args:
191-
configuration: Store configuration string
193+
configuration: Store configuration as string or tuple
192194
create: If True, a store will be created if it doesn't exist.
193195
If False and the store doesn't exist, an exception is raised.
194196

0 commit comments

Comments
 (0)