|
12 | 12 | from datetime import datetime |
13 | 13 | from io import open |
14 | 14 |
|
| 15 | +from litecli import sqlexecute |
| 16 | + |
15 | 17 | try: |
16 | 18 | from sqlean import OperationalError, sqlite_version |
17 | 19 | except ImportError: |
18 | 20 | from sqlite3 import OperationalError, sqlite_version |
19 | 21 | from time import time |
20 | | -from typing import Any, Iterable |
| 22 | +from typing import Any, Iterable, cast |
21 | 23 |
|
22 | 24 | import click |
23 | 25 | import sqlparse |
24 | 26 | from cli_helpers.tabular_output import TabularOutputFormatter, preprocessors |
25 | 27 | from prompt_toolkit.auto_suggest import AutoSuggestFromHistory |
26 | | -from prompt_toolkit.completion import DynamicCompleter |
| 28 | +from prompt_toolkit.completion import Completion, DynamicCompleter |
27 | 29 | from prompt_toolkit.document import Document |
28 | 30 | from prompt_toolkit.enums import DEFAULT_BUFFER, EditingMode |
29 | 31 | from prompt_toolkit.filters import HasFocus, IsDone |
|
35 | 37 | ) |
36 | 38 | from prompt_toolkit.lexers import PygmentsLexer |
37 | 39 | from prompt_toolkit.shortcuts import CompleteStyle, PromptSession |
38 | | -from typing import cast |
39 | | -from prompt_toolkit.completion import Completion |
40 | 40 |
|
41 | 41 | from .__init__ import __version__ |
42 | 42 | from .clibuffer import cli_is_multiline |
|
53 | 53 | from .sqlcompleter import SQLCompleter |
54 | 54 | from .sqlexecute import SQLExecute |
55 | 55 |
|
56 | | -click.disable_unicode_literals_warning = True |
57 | | - |
58 | 56 | # Query tuples are used for maintaining history |
59 | 57 | Query = namedtuple("Query", ["query", "successful", "mutating"]) |
60 | 58 |
|
@@ -84,7 +82,7 @@ def __init__( |
84 | 82 | self.key_bindings = c["main"]["key_bindings"] |
85 | 83 | special.set_favorite_queries(self.config) |
86 | 84 | self.formatter = TabularOutputFormatter(format_name=c["main"]["table_format"]) |
87 | | - self.formatter.litecli = self |
| 85 | + self.formatter.litecli = self # ty: ignore[unresolved-attribute] |
88 | 86 | self.syntax_style = c["main"]["syntax_style"] |
89 | 87 | self.less_chatty = c["main"].as_bool("less_chatty") |
90 | 88 | self.show_bottom_toolbar = c["main"].as_bool("show_bottom_toolbar") |
@@ -200,11 +198,14 @@ def change_db(self, arg: str | None, **_: Any) -> Iterable[tuple]: |
200 | 198 | self.sqlexecute.connect(database=arg) |
201 | 199 |
|
202 | 200 | self.refresh_completions() |
| 201 | + # guard so that ty doesn't complain |
| 202 | + dbname = self.sqlexecute.dbname if self.sqlexecute is not None else "" |
| 203 | + |
203 | 204 | yield ( |
204 | 205 | None, |
205 | 206 | None, |
206 | 207 | None, |
207 | | - 'You are now connected to database "%s"' % (self.sqlexecute.dbname), |
| 208 | + 'You are now connected to database "%s"' % (dbname), |
208 | 209 | ) |
209 | 210 |
|
210 | 211 | def execute_from_file(self, arg: str | None, **_: Any) -> Iterable[tuple[Any, ...]]: |
|
0 commit comments