diff --git a/rdflib/graph.py b/rdflib/graph.py index 3a84dcf246..b3d16c4819 100644 --- a/rdflib/graph.py +++ b/rdflib/graph.py @@ -562,7 +562,9 @@ def rollback(self: _GraphT) -> _GraphT: self.__store.rollback() return self - def open(self, configuration: str, create: bool = False) -> Optional[int]: + def open( + self, configuration: Union[str, tuple[str, str]], create: bool = False + ) -> Optional[int]: """Open the graph store Might be necessary for stores that require opening a connection to a @@ -2824,7 +2826,7 @@ def commit(self) -> NoReturn: def rollback(self) -> NoReturn: raise ModificationException() - def open(self, configuration: str, create: bool = False) -> None: + def open(self, configuration: str | tuple[str, str], create: bool = False) -> None: # TODO: is there a use case for this method? for graph in self.graphs: # type error: Too many arguments for "open" of "Graph" diff --git a/rdflib/plugins/stores/auditable.py b/rdflib/plugins/stores/auditable.py index b8fb534195..ca2c7d79b0 100644 --- a/rdflib/plugins/stores/auditable.py +++ b/rdflib/plugins/stores/auditable.py @@ -18,7 +18,7 @@ from __future__ import annotations import threading -from typing import TYPE_CHECKING, Any, Generator, Iterator, List, Optional, Tuple +from typing import TYPE_CHECKING, Any, Generator, Iterator, List, Optional, Tuple, Union from rdflib.graph import ConjunctiveGraph, Graph from rdflib.store import Store @@ -62,7 +62,9 @@ def __init__(self, store: Store): ] = [] self.rollbackLock = threading.RLock() - def open(self, configuration: str, create: bool = True) -> Optional[int]: + def open( + self, configuration: Union[str, tuple[str, str]], create: bool = True + ) -> Optional[int]: return self.store.open(configuration, create) def close(self, commit_pending_transaction: bool = False) -> None: diff --git a/rdflib/plugins/stores/berkeleydb.py b/rdflib/plugins/stores/berkeleydb.py index 12009787cd..11195432f3 100644 --- a/rdflib/plugins/stores/berkeleydb.py +++ b/rdflib/plugins/stores/berkeleydb.py @@ -4,7 +4,17 @@ from os import mkdir from os.path import abspath, exists from threading import Thread -from typing import TYPE_CHECKING, Any, Callable, Dict, Generator, List, Optional, Tuple +from typing import ( + TYPE_CHECKING, + Any, + Callable, + Dict, + Generator, + List, + Optional, + Tuple, + Union, +) from urllib.request import pathname2url from rdflib.store import NO_STORE, VALID_STORE, Store @@ -127,10 +137,16 @@ def _init_db_environment( def is_open(self) -> bool: return self.__open - def open(self, path: str, create: bool = True) -> Optional[int]: + def open( + self, configuration: Union[str, tuple[str, str]], create: bool = True + ) -> Optional[int]: if not has_bsddb: return NO_STORE - homeDir = path # noqa: N806 + + if type(configuration) is str: + homeDir = configuration # noqa: N806 + else: + raise Exception("Invalid configuration provided") if self.__identifier is None: self.__identifier = URIRef(pathname2url(abspath(homeDir))) diff --git a/rdflib/plugins/stores/sparqlstore.py b/rdflib/plugins/stores/sparqlstore.py index e7a9723e8c..d63986b143 100644 --- a/rdflib/plugins/stores/sparqlstore.py +++ b/rdflib/plugins/stores/sparqlstore.py @@ -148,11 +148,11 @@ def __init__( self._queries = 0 # type error: Missing return statement - def open(self, configuration: str, create: bool = False) -> Optional[int]: # type: ignore[return] + def open(self, configuration: Union[str, tuple[str, str]], create: bool = False) -> Optional[int]: # type: ignore[return] """This method is included so that calls to this Store via Graph, e.g. Graph("SPARQLStore"), can set the required parameters """ - if type(configuration) == str: # noqa: E721 + if type(configuration) is str: self.query_endpoint = configuration else: raise Exception( diff --git a/rdflib/store.py b/rdflib/store.py index 9cada631d7..86dabf1854 100644 --- a/rdflib/store.py +++ b/rdflib/store.py @@ -205,9 +205,10 @@ def node_pickler(self) -> NodePickler: def create(self, configuration: str) -> None: self.dispatcher.dispatch(StoreCreatedEvent(configuration=configuration)) - def open(self, configuration: str, create: bool = False) -> Optional[int]: - """ - Opens the store specified by the configuration string. If + def open( + self, configuration: Union[str, tuple[str, str]], create: bool = False + ) -> Optional[int]: + """Opens the store specified by the configuration string or tuple. If create is True a store will be created if it does not already exist. If create is False and a store does not already exist an exception is raised. An exception is also raised if a store