@@ -137,6 +137,8 @@ def close(self, save: str = None, conn_names: list[str] = None) -> None:
137137 :param conn_names: The optional list of connection names to close. If not defined, all opened connections are closed.
138138 """
139139 self .errors = {}
140+ if not self .conns :
141+ return
140142 selected_conns = self ._get_selected_connections (conn_names )
141143 selected_names = {conn .get_name () for conn in selected_conns }
142144 for conn in selected_conns :
@@ -158,15 +160,18 @@ def has_connections(self) -> bool:
158160
159161 :return: True if some connections were opened, False otherwise
160162 """
161- return len (self .conns ) > 0
163+ return self . conns and len (self .conns ) > 0
162164
163165 def get_connection_names (self ) -> list [str ]:
164166 """
165167 Get the opened connection names.
166168
167169 :return: The list of opened connection names
168170 """
169- return [conn .get_name () for conn in self .conns ]
171+ if self .conns :
172+ return [conn .get_name () for conn in self .conns ]
173+ else :
174+ return []
170175
171176 def has_errors (self ) -> bool :
172177 """
@@ -372,7 +377,7 @@ def sessions(self) -> dict:
372377 """
373378 rval = {}
374379 self ._init_errors ()
375- if len (self .conns ) == 0 :
380+ if not self . conns or len (self .conns ) == 0 :
376381 return rval
377382
378383 started_conns = []
@@ -422,7 +427,7 @@ def sessions(self) -> dict:
422427 if len (excluded_conns ) > 0 :
423428 logging .error (f"Some sessions have been excluded due to errors: { ', ' .join (excluded_conns )} " )
424429 self .conns = [conn for conn in self .conns if conn .get_name () not in excluded_conns ]
425- if len (self .conns ) == len ( excluded_conns ) :
430+ if len (self .conns ) == 0 :
426431 raise DSError ("No sessions could be started successfully." )
427432 return rval
428433
0 commit comments