Skip to content

Commit 74ab511

Browse files
handlers: fix typing and docs (#143)
pyrogram/pyrogram#701 Co-authored-by: Adek Maulana <[email protected]>
1 parent 3ac5829 commit 74ab511

22 files changed

+257
-54
lines changed

docs/source/releases/changes-in-this-fork.rst

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Changes in this Fork
2626
| Scheme layer used: 198 |
2727
+------------------------+
2828

29+
- PR from upstream: `701 <https://github.com/pyrogram/pyrogram/pull/701>`_
2930
- View `new and changed <https://telegramplayground.github.io/TG-APIs/TL/diff/tdlib.html?from=196&to=198>`__ `raw API methods <https://telegramplayground.github.io/TG-APIs/TL/diff/tdesktop.html?from=196&to=198>`__.
3031

3132
+------------------------+

pyrogram/handlers/business_bot_connection_handler.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,20 @@
1616
# You should have received a copy of the GNU Lesser General Public License
1717
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818

19-
from typing import Callable
19+
from typing import Any, Callable
2020

21+
import pyrogram
22+
from pyrogram.filters import Filter
2123
from .handler import Handler
2224

25+
CallbackFunc: Callable = Callable[
26+
[
27+
"pyrogram.Client",
28+
pyrogram.types.BusinessConnection
29+
],
30+
Any
31+
]
32+
2333

2434
class BusinessBotConnectionHandler(Handler):
2535
"""The Bot Business Connection handler class. Used to handle new bot business connection.
@@ -47,5 +57,5 @@ class BusinessBotConnectionHandler(Handler):
4757
4858
"""
4959

50-
def __init__(self, callback: Callable, filters=None):
60+
def __init__(self, callback: CallbackFunc, filters: Filter = None):
5161
super().__init__(callback, filters)

pyrogram/handlers/callback_query_handler.py

+15-4
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,21 @@
1616
# You should have received a copy of the GNU Lesser General Public License
1717
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818

19-
from typing import Callable
2019

20+
from typing import Any, Callable
21+
22+
import pyrogram
23+
from pyrogram.filters import Filter
2124
from .handler import Handler
2225

26+
CallbackFunc: Callable = Callable[
27+
[
28+
"pyrogram.Client",
29+
pyrogram.types.CallbackQuery
30+
],
31+
Any
32+
]
33+
2334

2435
class CallbackQueryHandler(Handler):
2536
"""The CallbackQuery handler class. Used to handle callback queries coming from inline buttons.
@@ -33,17 +44,17 @@ class CallbackQueryHandler(Handler):
3344
Pass a function that will be called when a new CallbackQuery arrives. It takes *(client, callback_query)*
3445
as positional arguments (look at the section below for a detailed description).
3546
36-
filters (:obj:`Filters`):
47+
filters (:obj:`Filter`):
3748
Pass one or more filters to allow only a subset of callback queries to be passed
3849
in your callback function.
3950
4051
Other parameters:
4152
client (:obj:`~pyrogram.Client`):
42-
The Client itself, useful when you want to call other API methods inside the message handler.
53+
The Client itself, useful when you want to call other API methods inside the callback query handler.
4354
4455
callback_query (:obj:`~pyrogram.types.CallbackQuery`):
4556
The received callback query.
4657
"""
4758

48-
def __init__(self, callback: Callable, filters=None):
59+
def __init__(self, callback: CallbackFunc, filters: Filter = None):
4960
super().__init__(callback, filters)

pyrogram/handlers/chat_join_request_handler.py

+13-2
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,20 @@
1616
# You should have received a copy of the GNU Lesser General Public License
1717
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818

19-
from typing import Callable
19+
from typing import Any, Callable
2020

21+
import pyrogram
22+
from pyrogram.filters import Filter
2123
from .handler import Handler
2224

25+
CallbackFunc: Callable = Callable[
26+
[
27+
"pyrogram.Client",
28+
pyrogram.types.ChatJoinRequest
29+
],
30+
Any
31+
]
32+
2333

2434
class ChatJoinRequestHandler(Handler):
2535
"""The ChatJoinRequest handler class. Used to handle join chat requests.
@@ -43,7 +53,8 @@ class ChatJoinRequestHandler(Handler):
4353
4454
chat_join_request (:obj:`~pyrogram.types.ChatJoinRequest`):
4555
The received chat join request.
56+
4657
"""
4758

48-
def __init__(self, callback: Callable, filters=None):
59+
def __init__(self, callback: CallbackFunc, filters: Filter = None):
4960
super().__init__(callback, filters)

pyrogram/handlers/chat_member_updated_handler.py

+16-4
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,20 @@
1616
# You should have received a copy of the GNU Lesser General Public License
1717
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818

19-
from typing import Callable
19+
from typing import Any, Callable
2020

21+
import pyrogram
22+
from pyrogram.filters import Filter
2123
from .handler import Handler
2224

25+
CallbackFunc: Callable = Callable[
26+
[
27+
"pyrogram.Client",
28+
pyrogram.types.ChatMemberUpdated
29+
],
30+
Any
31+
]
32+
2333

2434
class ChatMemberUpdatedHandler(Handler):
2535
"""The ChatMemberUpdated handler class. Used to handle changes in the status of a chat member.
@@ -34,16 +44,18 @@ class ChatMemberUpdatedHandler(Handler):
3444
*(client, chat_member_updated)* as positional arguments (look at the section below for a detailed
3545
description).
3646
37-
filters (:obj:`Filters`):
47+
filters (:obj:`Filter`):
3848
Pass one or more filters to allow only a subset of updates to be passed in your callback function.
3949
4050
Other parameters:
4151
client (:obj:`~pyrogram.Client`):
42-
The Client itself, useful when you want to call other API methods inside the handler.
52+
The Client itself, useful when you want to call other API methods inside the chat member updated
53+
handler.
4354
4455
chat_member_updated (:obj:`~pyrogram.types.ChatMemberUpdated`):
4556
The received chat member update.
57+
4658
"""
4759

48-
def __init__(self, callback: Callable, filters=None):
60+
def __init__(self, callback: CallbackFunc, filters: Filter = None):
4961
super().__init__(callback, filters)

pyrogram/handlers/chosen_inline_result_handler.py

+16-4
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,20 @@
1616
# You should have received a copy of the GNU Lesser General Public License
1717
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818

19-
from typing import Callable
19+
from typing import Any, Callable
2020

21+
import pyrogram
22+
from pyrogram.filters import Filter
2123
from .handler import Handler
2224

25+
CallbackFunc: Callable = Callable[
26+
[
27+
"pyrogram.Client",
28+
pyrogram.types.ChosenInlineResult
29+
],
30+
Any
31+
]
32+
2333

2434
class ChosenInlineResultHandler(Handler):
2535
"""The ChosenInlineResultHandler handler class. Used to handle chosen inline results coming from inline queries.
@@ -38,17 +48,19 @@ class ChosenInlineResultHandler(Handler):
3848
It takes *(client, chosen_inline_result)* as positional arguments (look at the section below for a
3949
detailed description).
4050
41-
filters (:obj:`Filters`):
51+
filters (:obj:`Filter`):
4252
Pass one or more filters to allow only a subset of chosen inline results to be passed
4353
in your callback function.
4454
4555
Other parameters:
4656
client (:obj:`~pyrogram.Client`):
47-
The Client itself, useful when you want to call other API methods inside the message handler.
57+
The Client itself, useful when you want to call other API methods inside the choose inline result
58+
handler.
4859
4960
chosen_inline_result (:obj:`~pyrogram.types.ChosenInlineResult`):
5061
The received chosen inline result.
62+
5163
"""
5264

53-
def __init__(self, callback: Callable, filters=None):
65+
def __init__(self, callback: CallbackFunc, filters: Filter = None):
5466
super().__init__(callback, filters)

pyrogram/handlers/deleted_messages_handler.py

+13-4
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,21 @@
1616
# You should have received a copy of the GNU Lesser General Public License
1717
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818

19-
from typing import Callable
19+
from typing import Any, Callable
2020

2121
import pyrogram
2222
from pyrogram.filters import Filter
2323
from pyrogram.types import Message
2424
from .handler import Handler
2525

26+
CallbackFunc: Callable = Callable[
27+
[
28+
"pyrogram.Client",
29+
list[Message]
30+
],
31+
Any
32+
]
33+
2634

2735
class DeletedMessagesHandler(Handler):
2836
"""The deleted messages handler class. Used to handle deleted messages coming from any chat
@@ -36,19 +44,20 @@ class DeletedMessagesHandler(Handler):
3644
Pass a function that will be called when one or more messages have been deleted.
3745
It takes *(client, messages)* as positional arguments (look at the section below for a detailed description).
3846
39-
filters (:obj:`Filters`):
47+
filters (:obj:`Filter`):
4048
Pass one or more filters to allow only a subset of messages to be passed
4149
in your callback function.
4250
4351
Other parameters:
4452
client (:obj:`~pyrogram.Client`):
45-
The Client itself, useful when you want to call other API methods inside the message handler.
53+
The Client itself, useful when you want to call other API methods inside the deleted message handler.
4654
4755
messages (List of :obj:`~pyrogram.types.Message`):
4856
The deleted messages, as list.
57+
4958
"""
5059

51-
def __init__(self, callback: Callable, filters: Filter = None):
60+
def __init__(self, callback: CallbackFunc, filters: Filter = None):
5261
super().__init__(callback, filters)
5362

5463
async def check(self, client: "pyrogram.Client", messages: list[Message]):

pyrogram/handlers/disconnect_handler.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,13 @@
1616
# You should have received a copy of the GNU Lesser General Public License
1717
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818

19-
from typing import Callable
19+
from typing import Any, Callable
2020

21+
import pyrogram
2122
from .handler import Handler
2223

24+
CallbackFunc: Callable = Callable[["pyrogram.Client"], Any]
25+
2326

2427
class DisconnectHandler(Handler):
2528
"""The Disconnect handler class. Used to handle disconnections. It is intended to be used with
@@ -37,7 +40,8 @@ class DisconnectHandler(Handler):
3740
client (:obj:`~pyrogram.Client`):
3841
The Client itself. Useful, for example, when you want to change the proxy before a new connection
3942
is established.
43+
4044
"""
4145

42-
def __init__(self, callback: Callable):
46+
def __init__(self, callback: CallbackFunc):
4347
super().__init__(callback)

pyrogram/handlers/edited_message_handler.py

+13-2
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,20 @@
1616
# You should have received a copy of the GNU Lesser General Public License
1717
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818

19-
from typing import Callable
19+
from typing import Any, Callable
2020

21+
import pyrogram
22+
from pyrogram.filters import Filter
2123
from .handler import Handler
2224

25+
CallbackFunc: Callable = Callable[
26+
[
27+
"pyrogram.Client",
28+
pyrogram.types.Message
29+
],
30+
Any
31+
]
32+
2333

2434
class EditedMessageHandler(Handler):
2535
"""The EditedMessage handler class. Used to handle edited messages.
@@ -43,7 +53,8 @@ class EditedMessageHandler(Handler):
4353
4454
edited_message (:obj:`~pyrogram.types.Message`):
4555
The received edited message.
56+
4657
"""
4758

48-
def __init__(self, callback: Callable, filters=None):
59+
def __init__(self, callback: CallbackFunc, filters: Filter = None):
4960
super().__init__(callback, filters)

pyrogram/handlers/handler.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,17 @@
1717
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818

1919
import inspect
20-
from typing import Callable
20+
from typing import Any, Callable
2121

2222
import pyrogram
2323
from pyrogram.filters import Filter
2424
from pyrogram.types import Update
2525

26+
CallbackFunc: Callable = Callable[..., Any]
27+
2628

2729
class Handler:
28-
def __init__(self, callback: Callable, filters: Filter = None):
30+
def __init__(self, callback: CallbackFunc, filters: Filter = None):
2931
self.callback = callback
3032
self.filters = filters
3133

pyrogram/handlers/inline_query_handler.py

+14-3
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,20 @@
1616
# You should have received a copy of the GNU Lesser General Public License
1717
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818

19-
from typing import Callable
19+
from typing import Any, Callable
2020

21+
import pyrogram
22+
from pyrogram.filters import Filter
2123
from .handler import Handler
2224

25+
CallbackFunc: Callable = Callable[
26+
[
27+
"pyrogram.Client",
28+
pyrogram.types.InlineQuery
29+
],
30+
Any
31+
]
32+
2333

2434
class InlineQueryHandler(Handler):
2535
"""The InlineQuery handler class. Used to handle inline queries.
@@ -33,7 +43,7 @@ class InlineQueryHandler(Handler):
3343
Pass a function that will be called when a new InlineQuery arrives. It takes *(client, inline_query)*
3444
as positional arguments (look at the section below for a detailed description).
3545
36-
filters (:obj:`Filters`):
46+
filters (:obj:`Filter`):
3747
Pass one or more filters to allow only a subset of inline queries to be passed
3848
in your callback function.
3949
@@ -43,7 +53,8 @@ class InlineQueryHandler(Handler):
4353
4454
inline_query (:obj:`~pyrogram.types.InlineQuery`):
4555
The received inline query.
56+
4657
"""
4758

48-
def __init__(self, callback: Callable, filters=None):
59+
def __init__(self, callback: CallbackFunc, filters: Filter = None):
4960
super().__init__(callback, filters)

0 commit comments

Comments
 (0)