From 482629ac188d255b7ccf70df2e91a3f3ab5ee7c4 Mon Sep 17 00:00:00 2001 From: Andrew <11490628+andrew000@users.noreply.github.com> Date: Sat, 26 Apr 2025 16:18:49 +0300 Subject: [PATCH] Fix for #1677 (#1678) * Make `as_markup` return `super().as_markup` * Add 1677.misc.rst * Update 1677.misc.rst --- CHANGES/1677.misc.rst | 5 +++++ aiogram/utils/keyboard.py | 14 ++++++-------- 2 files changed, 11 insertions(+), 8 deletions(-) create mode 100644 CHANGES/1677.misc.rst diff --git a/CHANGES/1677.misc.rst b/CHANGES/1677.misc.rst new file mode 100644 index 00000000..ce0de8c1 --- /dev/null +++ b/CHANGES/1677.misc.rst @@ -0,0 +1,5 @@ +Fixed MyPy [return-value] error in `InlineKeyboardBuilder().as_markup()`. +`as_markup` method now overloads parent class method and uses `super()`, to call parent's +`as_markup` method. +Also added correct type hint to `as_markup`'s return in `InlineKeyboardBuilder` and +`ReplyKeyboardBuilder` classes. diff --git a/aiogram/utils/keyboard.py b/aiogram/utils/keyboard.py index fe806f7a..8caa02b5 100644 --- a/aiogram/utils/keyboard.py +++ b/aiogram/utils/keyboard.py @@ -336,11 +336,9 @@ class InlineKeyboardBuilder(KeyboardBuilder[InlineKeyboardButton]): ), ) - if TYPE_CHECKING: - - def as_markup(self, **kwargs: Any) -> InlineKeyboardMarkup: - """Construct an InlineKeyboardMarkup""" - ... + def as_markup(self, **kwargs: Any) -> InlineKeyboardMarkup: + """Construct an InlineKeyboardMarkup""" + return cast(InlineKeyboardMarkup, super().as_markup(**kwargs)) def __init__(self, markup: Optional[List[List[InlineKeyboardButton]]] = None) -> None: super().__init__(button_type=InlineKeyboardButton, markup=markup) @@ -401,9 +399,9 @@ class ReplyKeyboardBuilder(KeyboardBuilder[KeyboardButton]): ), ) - if TYPE_CHECKING: - - def as_markup(self, **kwargs: Any) -> ReplyKeyboardMarkup: ... + def as_markup(self, **kwargs: Any) -> ReplyKeyboardMarkup: + """Construct a ReplyKeyboardMarkup""" + return cast(ReplyKeyboardMarkup, super().as_markup(**kwargs)) def __init__(self, markup: Optional[List[List[KeyboardButton]]] = None) -> None: super().__init__(button_type=KeyboardButton, markup=markup)