@@ -61,7 +61,7 @@ def dir_where(self) -> bool:
6161 return self .dir and self .where and not self .key
6262
6363
64- def at (* path , key : str = None , where : Callable [[Any , Any ], bool ] = None ) -> DDBMethodChooser :
64+ def at (* path , key : str | None = None , where : Callable [[Any , Any ], bool ] | None = None ) -> DDBMethodChooser :
6565 """
6666 Select a file or folder to perform an operation on.
6767 If you want to select a specific key in a file, use the `key` parameter,
@@ -98,8 +98,8 @@ class DDBMethodChooser:
9898 def __init__ (
9999 self ,
100100 path : tuple ,
101- key : str = None ,
102- where : Callable [[Any , Any ], bool ] = None ,
101+ key : str | None = None ,
102+ where : Callable [[Any , Any ], bool ] | None = None ,
103103 ) -> None :
104104 # Convert path to a list of strings
105105 pc = []
@@ -146,13 +146,13 @@ def create(self, data: dict | None = None, force_overwrite: bool = False) -> Non
146146 exists, defaults to False (optional).
147147 """
148148 if self .where is not None or self .key is not None :
149- raise RuntimeError ("DDB.at().create() cannot be used with the where or key parameters" )
149+ msg = "DDB.at().create() cannot be used with the where or key parameters"
150+ raise RuntimeError (msg )
150151
151152 # Except if db exists and force_overwrite is False
152153 if not force_overwrite and self .exists ():
153- raise FileExistsError (
154- f"Database { self .path } already exists in { config .storage_directory } . Pass force_overwrite=True to overwrite."
155- )
154+ msg = f"Database { self .path } already exists in { config .storage_directory } . Pass force_overwrite=True to overwrite."
155+ raise FileExistsError (msg )
156156 # Write db to file
157157 if data is None :
158158 data = {}
@@ -166,7 +166,7 @@ def delete(self) -> None:
166166 raise RuntimeError ("DDB.at().delete() cannot be used with the where or key parameters" )
167167 io_safe .delete (self .path )
168168
169- def read (self , as_type : Type [T ] = None ) -> dict | T | None :
169+ def read (self , as_type : Type [T ] | None = None ) -> dict | T | None :
170170 """
171171 Reads a file or folder depending on previous `.at(...)` selection.
172172
@@ -209,7 +209,7 @@ def type_cast(value):
209209 return type_cast (data )
210210
211211 def session (
212- self , as_type : Type [T ] = None
212+ self , as_type : Type [T ] | None = None
213213 ) -> SessionFileFull [T ] | SessionFileKey [T ] | SessionFileWhere [T ] | SessionDirFull [T ] | SessionDirWhere [T ]:
214214 """
215215 Opens a session to the selected file(s) or folder, depending on previous
@@ -228,6 +228,7 @@ def session(
228228 Returns:
229229 - Tuple of (session_object, data)
230230 """
231+
231232 if self .op_type .file_normal :
232233 return SessionFileFull (self .path , as_type )
233234 if self .op_type .file_key :
@@ -238,3 +239,6 @@ def session(
238239 return SessionDirFull (self .path , as_type )
239240 if self .op_type .dir_where :
240241 return SessionDirWhere (self .path , self .where , as_type )
242+
243+ msg = "Invalid operation type"
244+ raise RuntimeError (msg )
0 commit comments