From daedec6957df125b012854282b194ba90b59d28a Mon Sep 17 00:00:00 2001 From: teknium1 Date: Mon, 2 Mar 2026 22:03:36 -0800 Subject: [PATCH] fix: Telegram adapter crash on Windows when library not installed (#304) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- gateway/platforms/telegram.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/gateway/platforms/telegram.py b/gateway/platforms/telegram.py index 076e97ff..1e4d2ab8 100644 --- a/gateway/platforms/telegram.py +++ b/gateway/platforms/telegram.py @@ -29,7 +29,17 @@ except ImportError: Bot = Any Message = 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 from pathlib import Path as _Path