1313from io import open
1414
1515try :
16- from sqlean import OperationalError , sqlite_version # ty : ignore[unresolved- import]
16+ from sqlean import OperationalError , sqlite_version # type : ignore[import-untyped ]
1717except ImportError :
1818 from sqlite3 import OperationalError , sqlite_version
1919from time import time
@@ -80,7 +80,8 @@ def __init__(
8080 self .key_bindings = c ["main" ]["key_bindings" ]
8181 special .set_favorite_queries (self .config )
8282 self .formatter = TabularOutputFormatter (format_name = c ["main" ]["table_format" ])
83- self .formatter .litecli = self # ty: ignore[unresolved-attribute]
83+ # self.formatter.litecli = self, ty raises unresolved-attribute, hence use dynamic assignment
84+ setattr (self .formatter , "litecli" , self )
8485 self .syntax_style = c ["main" ]["syntax_style" ]
8586 self .less_chatty = c ["main" ].as_bool ("less_chatty" )
8687 self .show_bottom_toolbar = c ["main" ].as_bool ("show_bottom_toolbar" )
@@ -302,7 +303,7 @@ def get(key: str) -> str | None:
302303
303304 return {x : get (x ) for x in keys }
304305
305- def connect (self , database : str = "" ) -> None :
306+ def connect (self , database : str | None = "" ) -> None :
306307 cnf : dict [str , str | None ] = {"database" : None }
307308
308309 cnf = self .read_my_cnf_files (cnf .keys ())
@@ -509,8 +510,8 @@ def one_iteration(text: str | None = None) -> None:
509510 successful = False
510511 start = time ()
511512 res = sqlexecute .run (text )
512- # Ty complains about dynamic assignment. Since the code from the library, ignore the assignment error
513- self .formatter . query = text # ty: ignore[invalid-assignment]
513+ # Set query attribute dynamically on formatter
514+ setattr ( self .formatter , " query" , text )
514515 successful = True
515516 special .unset_once_if_written ()
516517 # Keep track of whether or not the query is mutating. In case
@@ -523,7 +524,7 @@ def one_iteration(text: str | None = None) -> None:
523524 except KeyboardInterrupt :
524525 try :
525526 # since connection can sqlite3 or sqlean, it's hard to annotate the type for interrupt. so ignore the type hint warning.
526- sqlexecute .conn .interrupt () # ty : ignore[possibly-missing-attribute ]
527+ sqlexecute .conn .interrupt () # type : ignore[attr-defined ]
527528 except Exception as e :
528529 self .echo (
529530 "Encountered error while cancelling query: {}" .format (e ),
@@ -817,7 +818,7 @@ def run_query(self, query: str, new_line: bool = True) -> None:
817818 results = self .sqlexecute .run (query )
818819 for result in results :
819820 title , cur , headers , status = result
820- self .formatter . query = query # ty: ignore[invalid-assignment]
821+ setattr ( self .formatter , " query" , query )
821822 output = self .format_output (title , cur , headers )
822823 for line in output :
823824 click .echo (line , nl = new_line )
0 commit comments