Fix for #1677 (#1678)
Some checks failed
Tests / tests (macos-latest, 3.10) (push) Has been cancelled
Tests / tests (macos-latest, 3.11) (push) Has been cancelled
Tests / tests (macos-latest, 3.12) (push) Has been cancelled
Tests / tests (macos-latest, 3.13) (push) Has been cancelled
Tests / tests (macos-latest, 3.9) (push) Has been cancelled
Tests / tests (ubuntu-latest, 3.10) (push) Has been cancelled
Tests / tests (ubuntu-latest, 3.11) (push) Has been cancelled
Tests / tests (ubuntu-latest, 3.12) (push) Has been cancelled
Tests / tests (ubuntu-latest, 3.13) (push) Has been cancelled
Tests / tests (ubuntu-latest, 3.9) (push) Has been cancelled
Tests / tests (windows-latest, 3.10) (push) Has been cancelled
Tests / tests (windows-latest, 3.11) (push) Has been cancelled
Tests / tests (windows-latest, 3.12) (push) Has been cancelled
Tests / tests (windows-latest, 3.13) (push) Has been cancelled
Tests / tests (windows-latest, 3.9) (push) Has been cancelled
Tests / pypy-tests (macos-latest, pypy3.10) (push) Has been cancelled
Tests / pypy-tests (macos-latest, pypy3.9) (push) Has been cancelled
Tests / pypy-tests (ubuntu-latest, pypy3.10) (push) Has been cancelled
Tests / pypy-tests (ubuntu-latest, pypy3.9) (push) Has been cancelled

* Make `as_markup` return `super().as_markup`

* Add 1677.misc.rst

* Update 1677.misc.rst
This commit is contained in:
Andrew 2025-04-26 16:18:49 +03:00 committed by GitHub
parent 7a9ecdfbd9
commit 482629ac18
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 8 deletions

5
CHANGES/1677.misc.rst Normal file
View file

@ -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.

View file

@ -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)