mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-22 01:16:35 +03:00
Fix type annotation for keyboard buttons (#4438)
This commit is contained in:
parent
babeba46d3
commit
6253d28143
|
@ -1,11 +1,14 @@
|
|||
from typing import Optional, TypeAlias
|
||||
from typing import Generic, Optional, TypeAlias, TypeVar
|
||||
|
||||
from ...tl import abcs, types
|
||||
from .buttons.button import Button
|
||||
from .buttons import Button, InlineButton
|
||||
|
||||
AnyButton = TypeVar("AnyButton", bound=Button)
|
||||
AnyInlineButton = TypeVar("AnyInlineButton", bound=InlineButton)
|
||||
|
||||
|
||||
def _build_keyboard_rows(
|
||||
btns: list[Button] | list[list[Button]],
|
||||
btns: list[AnyButton] | list[list[AnyButton]],
|
||||
) -> list[abcs.KeyboardButtonRow]:
|
||||
# list[button] -> list[list[button]]
|
||||
# This does allow for "invalid" inputs (mixing lists and non-lists), but that's acceptable.
|
||||
|
@ -21,12 +24,12 @@ def _build_keyboard_rows(
|
|||
]
|
||||
|
||||
|
||||
class Keyboard:
|
||||
class Keyboard(Generic[AnyButton]):
|
||||
__slots__ = ("_raw",)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
buttons: list[Button] | list[list[Button]],
|
||||
buttons: list[AnyButton] | list[list[AnyButton]],
|
||||
resize: bool,
|
||||
single_use: bool,
|
||||
selective: bool,
|
||||
|
@ -43,10 +46,12 @@ class Keyboard:
|
|||
)
|
||||
|
||||
|
||||
class InlineKeyboard:
|
||||
class InlineKeyboard(Generic[AnyInlineButton]):
|
||||
__slots__ = ("_raw",)
|
||||
|
||||
def __init__(self, buttons: list[Button] | list[list[Button]]) -> None:
|
||||
def __init__(
|
||||
self, buttons: list[AnyInlineButton] | list[list[AnyInlineButton]]
|
||||
) -> None:
|
||||
self._raw = types.ReplyInlineMarkup(rows=_build_keyboard_rows(buttons))
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user