mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-08-08 04:52:30 +00:00
Add HiddenKeyboard and ForcedReplyKeyboard custom types and improve type annotation (#4481)
This commit is contained in:

committed by
GitHub

parent
61642c04a5
commit
771954d010
@@ -22,6 +22,7 @@ dependencies = [
|
||||
"pyaes~=1.6",
|
||||
"rsa~=4.9",
|
||||
"markdown-it-py~=3.0",
|
||||
"typing-extensions~=4.12.2",
|
||||
]
|
||||
dynamic = ["version"]
|
||||
|
||||
|
@@ -1,7 +1,9 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import AsyncIterator
|
||||
from typing import TYPE_CHECKING, Optional, Self
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
|
||||
from typing_extensions import Self
|
||||
|
||||
from ...session import PeerRef, UserRef
|
||||
from ...tl import abcs, functions, types
|
||||
|
@@ -4,7 +4,9 @@ import logging
|
||||
from collections.abc import AsyncIterator, Awaitable, Callable
|
||||
from pathlib import Path
|
||||
from types import TracebackType
|
||||
from typing import Any, Literal, Optional, Self, Sequence, Type, TypeVar
|
||||
from typing import Any, Literal, Optional, Sequence, Type, TypeVar
|
||||
|
||||
from typing_extensions import Self
|
||||
|
||||
from ....version import __version__ as default_version
|
||||
from ...mtsender import Connector, Sender
|
||||
|
@@ -2,7 +2,9 @@ from __future__ import annotations
|
||||
|
||||
import datetime
|
||||
import sys
|
||||
from typing import TYPE_CHECKING, Literal, Optional, Self
|
||||
from typing import TYPE_CHECKING, Literal, Optional
|
||||
|
||||
from typing_extensions import Self
|
||||
|
||||
from ...session import ChannelRef, PeerRef
|
||||
from ...tl import abcs, functions, types
|
||||
|
@@ -1,7 +1,9 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import abc
|
||||
from typing import TYPE_CHECKING, Optional, Self
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
|
||||
from typing_extensions import Self
|
||||
|
||||
from ...tl import abcs
|
||||
from ..types import NoPublicConstructor, Peer
|
||||
|
@@ -1,6 +1,8 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING, Optional, Self, Sequence
|
||||
from typing import TYPE_CHECKING, Optional, Sequence
|
||||
|
||||
from typing_extensions import Self
|
||||
|
||||
from ...tl import abcs, types
|
||||
from ..types import Message, Peer, expand_peer, peer_id
|
||||
|
@@ -1,6 +1,8 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING, Optional, Self
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
|
||||
from typing_extensions import Self
|
||||
|
||||
from ...session import PeerRef
|
||||
from ...tl import abcs, functions, types
|
||||
|
@@ -1,7 +1,9 @@
|
||||
import abc
|
||||
from collections import deque
|
||||
from collections.abc import Generator
|
||||
from typing import Any, Generic, Self, TypeVar
|
||||
from typing import Any, Generic, TypeVar
|
||||
|
||||
from typing_extensions import Self
|
||||
|
||||
T = TypeVar("T")
|
||||
|
||||
|
@@ -1,6 +1,8 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING, Optional, Self
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
|
||||
from typing_extensions import Self
|
||||
|
||||
from ...tl import abcs, types
|
||||
from .draft import Draft
|
||||
|
@@ -1,7 +1,9 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import datetime
|
||||
from typing import TYPE_CHECKING, Optional, Self
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
|
||||
from typing_extensions import Self
|
||||
|
||||
from ...session import PeerRef
|
||||
from ...tl import abcs, functions, types
|
||||
|
@@ -6,7 +6,9 @@ from collections.abc import Coroutine
|
||||
from inspect import isawaitable
|
||||
from io import BufferedWriter
|
||||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING, Any, Optional, Protocol, Self, Sequence
|
||||
from typing import TYPE_CHECKING, Any, Optional, Protocol, Sequence
|
||||
|
||||
from typing_extensions import Self
|
||||
|
||||
from ...tl import abcs, types
|
||||
from .meta import NoPublicConstructor
|
||||
|
@@ -1,4 +1,4 @@
|
||||
from typing import Self
|
||||
from typing_extensions import Self
|
||||
|
||||
from ...tl import types
|
||||
from .meta import NoPublicConstructor
|
||||
|
@@ -30,6 +30,7 @@ class Keyboard:
|
||||
def __init__(
|
||||
self,
|
||||
buttons: list[AnyButton] | list[list[AnyButton]],
|
||||
*,
|
||||
resize: bool,
|
||||
single_use: bool,
|
||||
selective: bool,
|
||||
@@ -55,4 +56,24 @@ class InlineKeyboard:
|
||||
self._raw = types.ReplyInlineMarkup(rows=_build_keyboard_rows(buttons))
|
||||
|
||||
|
||||
KeyboardType: TypeAlias = Keyboard | InlineKeyboard
|
||||
class HiddenKeyboard:
|
||||
__slots__ = ("_raw",)
|
||||
|
||||
def __init__(self, *, selective: bool) -> None:
|
||||
self._raw = types.ReplyKeyboardHide(selective=selective)
|
||||
|
||||
|
||||
class ForcedReplyKeyboard:
|
||||
__slots__ = ("_raw",)
|
||||
|
||||
def __init__(
|
||||
self, *, single_use: bool, selective: bool, placeholder: Optional[str]
|
||||
) -> None:
|
||||
self._raw = types.ReplyKeyboardForceReply(
|
||||
single_use=single_use, selective=selective, placeholder=placeholder
|
||||
)
|
||||
|
||||
|
||||
KeyboardType: TypeAlias = (
|
||||
Keyboard | InlineKeyboard | HiddenKeyboard | ForcedReplyKeyboard
|
||||
)
|
||||
|
@@ -1,4 +1,4 @@
|
||||
from typing import Self
|
||||
from typing_extensions import Self
|
||||
|
||||
from ...tl import types
|
||||
from .meta import NoPublicConstructor
|
||||
|
@@ -1,4 +1,6 @@
|
||||
from typing import Optional, Self
|
||||
from typing import Optional
|
||||
|
||||
from typing_extensions import Self
|
||||
|
||||
from ...tl import types
|
||||
from .meta import NoPublicConstructor
|
||||
|
@@ -2,7 +2,9 @@ from __future__ import annotations
|
||||
|
||||
import datetime
|
||||
import time
|
||||
from typing import TYPE_CHECKING, Any, Optional, Self, Sequence, cast
|
||||
from typing import TYPE_CHECKING, Any, Optional, Sequence, cast
|
||||
|
||||
from typing_extensions import Self
|
||||
|
||||
from ...session import PeerRef
|
||||
from ...tl import abcs, types
|
||||
|
@@ -1,7 +1,9 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import datetime
|
||||
from typing import TYPE_CHECKING, Optional, Self, Sequence
|
||||
from typing import TYPE_CHECKING, Optional, Sequence
|
||||
|
||||
from typing_extensions import Self
|
||||
|
||||
from ...session import ChannelRef, GroupRef
|
||||
from ...tl import abcs, types
|
||||
|
@@ -1,4 +1,4 @@
|
||||
from typing import Self
|
||||
from typing_extensions import Self
|
||||
|
||||
from ...tl import types
|
||||
from .meta import NoPublicConstructor
|
||||
|
@@ -1,4 +1,6 @@
|
||||
from typing import Optional, Self
|
||||
from typing import Optional
|
||||
|
||||
from typing_extensions import Self
|
||||
|
||||
from ....session import ChannelRef
|
||||
from ....tl import abcs, types
|
||||
|
@@ -1,7 +1,9 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import datetime
|
||||
from typing import TYPE_CHECKING, Optional, Self, Sequence
|
||||
from typing import TYPE_CHECKING, Optional, Sequence
|
||||
|
||||
from typing_extensions import Self
|
||||
|
||||
from ....session import ChannelRef, GroupRef
|
||||
from ....tl import abcs, types
|
||||
|
@@ -1,4 +1,6 @@
|
||||
from typing import Optional, Self
|
||||
from typing import Optional
|
||||
|
||||
from typing_extensions import Self
|
||||
|
||||
from ....session import UserRef
|
||||
from ....tl import abcs, types
|
||||
|
@@ -1,6 +1,7 @@
|
||||
from dataclasses import dataclass
|
||||
from hashlib import sha1
|
||||
from typing import Self
|
||||
|
||||
from typing_extensions import Self
|
||||
|
||||
|
||||
@dataclass
|
||||
|
@@ -1,7 +1,9 @@
|
||||
import logging
|
||||
import re
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import NewType, Optional, Self
|
||||
from typing import NewType, Optional
|
||||
|
||||
from typing_extensions import Self
|
||||
|
||||
from ...tl.mtproto.types import RpcError as GeneratedRpcError
|
||||
|
||||
|
@@ -6,7 +6,9 @@ from abc import ABC
|
||||
from asyncio import FIRST_COMPLETED, Event, Future
|
||||
from collections.abc import Iterator
|
||||
from dataclasses import dataclass
|
||||
from typing import Generic, Optional, Protocol, Self, Type, TypeVar
|
||||
from typing import Generic, Optional, Protocol, Type, TypeVar
|
||||
|
||||
from typing_extensions import Self
|
||||
|
||||
from ..crypto import AuthKey
|
||||
from ..mtproto import (
|
||||
|
@@ -4,7 +4,9 @@ import abc
|
||||
import base64
|
||||
import re
|
||||
import struct
|
||||
from typing import Optional, Self, TypeAlias
|
||||
from typing import Optional, TypeAlias
|
||||
|
||||
from typing_extensions import Self
|
||||
|
||||
from ...tl import abcs, types
|
||||
|
||||
|
@@ -1,6 +1,8 @@
|
||||
import abc
|
||||
import struct
|
||||
from typing import Protocol, Self
|
||||
from typing import Protocol
|
||||
|
||||
from typing_extensions import Self
|
||||
|
||||
from .reader import Reader
|
||||
|
||||
|
Reference in New Issue
Block a user