fix: Telegram adapter crash on Windows when library not installed (#304)
The ImportError fallback set ContextTypes = Any, but then ContextTypes.DEFAULT_TYPE was used as a type annotation at class definition time — Any doesn't have .DEFAULT_TYPE, causing AttributeError. Fix: create a _MockContextTypes class with DEFAULT_TYPE = Any. Also stub CommandHandler, TelegramMessageHandler, filters, ParseMode, and ChatType to prevent potential NameErrors. Fixes #304.
This commit is contained in:
parent
de59d91add
commit
daedec6957
1 changed files with 11 additions and 1 deletions
|
|
@ -29,7 +29,17 @@ except ImportError:
|
||||||
Bot = Any
|
Bot = Any
|
||||||
Message = Any
|
Message = Any
|
||||||
Application = Any
|
Application = Any
|
||||||
ContextTypes = Any
|
CommandHandler = Any
|
||||||
|
TelegramMessageHandler = Any
|
||||||
|
filters = None
|
||||||
|
ParseMode = None
|
||||||
|
ChatType = None
|
||||||
|
|
||||||
|
# Mock ContextTypes so type annotations using ContextTypes.DEFAULT_TYPE
|
||||||
|
# don't crash during class definition when the library isn't installed.
|
||||||
|
class _MockContextTypes:
|
||||||
|
DEFAULT_TYPE = Any
|
||||||
|
ContextTypes = _MockContextTypes
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
from pathlib import Path as _Path
|
from pathlib import Path as _Path
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue