diff --git a/frappe/__init__.py b/frappe/__init__.py index 7ed40024f9..cf29b45fd1 100644 --- a/frappe/__init__.py +++ b/frappe/__init__.py @@ -162,7 +162,9 @@ ResponseDict: TypeAlias = _dict[str, Any] # type: ignore[no-any-explicit] FlagsDict: TypeAlias = _dict[str, Any] # type: ignore[no-any-explicit] FormDict: TypeAlias = _dict[str, str] -db: LocalProxy[Union["PyMariaDBDatabase", "MariaDBDatabase", "PostgresDatabase", "SQLiteDatabase"]] = local("db") +db: LocalProxy[Union["PyMariaDBDatabase", "MariaDBDatabase", "PostgresDatabase", "SQLiteDatabase"]] = local( + "db" +) qb: LocalProxy[Union["MariaDB", "Postgres", "SQLite"]] = local("qb") conf: LocalProxy[ConfType] = local("conf") form_dict: LocalProxy[FormDict] = local("form_dict") diff --git a/frappe/database/database.py b/frappe/database/database.py index 41f5f91e75..baefad6c8b 100644 --- a/frappe/database/database.py +++ b/frappe/database/database.py @@ -38,14 +38,15 @@ from frappe.utils import CallbackManager, cint, get_datetime, get_table_name, ge from frappe.utils import cast as cast_fieldtype if TYPE_CHECKING: + from sqlite3 import Connection as SQLiteConnection + from sqlite3 import Cursor as SQLiteCursor + from MySQLdb.connections import Connection as MySQLdbConnection from MySQLdb.cursors import Cursor as MySQLdbCursor from psycopg2 import connection as PostgresConnection from psycopg2 import cursor as PostgresCursor from pymysql.connections import Connection as MariadbConnection from pymysql.cursors import Cursor as MariadbCursor - from sqlite3 import Connection as SQLiteConnection - from sqlite3 import Cursor as SQLiteCursor IFNULL_PATTERN = re.compile(r"ifnull\(", flags=re.IGNORECASE) INDEX_PATTERN = re.compile(r"\s*\([^)]+\)\s*") @@ -130,7 +131,9 @@ class Database: def connect(self): """Connects to a database as set in `site_config.json`.""" - self._conn: MySQLdbConnection | MariadbConnection | PostgresConnection | SQLiteConnection = self.get_connection() + self._conn: MySQLdbConnection | MariadbConnection | PostgresConnection | SQLiteConnection = ( + self.get_connection() + ) self._cursor: MySQLdbCursor | MariadbCursor | PostgresCursor | SQLiteCursor = self._conn.cursor() try: