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)