Raise ImportError and not ValueError when sqlite3 is missing

Excepting ValueError when creating the SQLiteSession could hide
other errors (e.g. using a newer session file on an older version
of the library). Instead, the original error is raised, as if
sqlite3 was being imported within its __init__ method.
This commit is contained in:
Lonami Exo 2019-02-13 08:51:26 +01:00
parent d25442345e
commit 47d9de98ed
2 changed files with 5 additions and 3 deletions

View File

@ -202,7 +202,7 @@ class TelegramBaseClient(abc.ABC):
if isinstance(session, str) or session is None:
try:
session = SQLiteSession(session)
except ValueError:
except ImportError:
import warnings
warnings.warn(
'The sqlite3 module is not available under this '

View File

@ -14,8 +14,10 @@ from ..tl.types import (
try:
import sqlite3
except ImportError:
sqlite3_err = None
except ImportError as e:
sqlite3 = None
sqlite3_err = type(e)
EXTENSION = '.session'
CURRENT_VERSION = 5 # database version
@ -32,7 +34,7 @@ class SQLiteSession(MemorySession):
def __init__(self, session_id=None):
if sqlite3 is None:
raise ValueError('sqlite3 is not installed')
raise sqlite3_err
super().__init__()
self.filename = ':memory:'