File tree Expand file tree Collapse file tree 1 file changed +20
-2
lines changed
Expand file tree Collapse file tree 1 file changed +20
-2
lines changed Original file line number Diff line number Diff line change 22
33import asyncio
44import json
5- import sqlite3
5+ import sys
66import threading
77from collections .abc import Iterator
88from contextlib import contextmanager
99from pathlib import Path
10- from typing import ClassVar
10+ from typing import TYPE_CHECKING , ClassVar
1111
1212from ..items import TResponseInputItem
1313from .session import SessionABC
1414from .session_settings import SessionSettings , resolve_session_limit
1515
16+ if TYPE_CHECKING :
17+ import sqlite3
18+ else :
19+ sqlite3 = sys .modules .get ("sqlite3" )
20+ if sqlite3 is None :
21+ try :
22+ import sqlite3 as _sqlite3
23+
24+ sqlite3 = _sqlite3
25+ except ImportError :
26+ sqlite3 = None # type: ignore[misc,assignment]
27+
1628
1729class SQLiteSession (SessionABC ):
1830 """SQLite-based implementation of session storage.
@@ -46,6 +58,12 @@ def __init__(
4658 session_settings: Session configuration settings including default limit for
4759 retrieving items. If None, uses default SessionSettings().
4860 """
61+ if sqlite3 is None :
62+ raise RuntimeError (
63+ "SQLiteSession requires the sqlite3 module, which is not available "
64+ "in this Python runtime. Please install a Python build with sqlite3 support "
65+ "or use an alternative session implementation."
66+ )
4967 self .session_id = session_id
5068 self .session_settings = session_settings or SessionSettings ()
5169 self .db_path = db_path
You can’t perform that action at this time.
0 commit comments