Skip to content

Commit 1737ba5

Browse files
committed
Revamp docs about the main Pyrogram package
1 parent ee91e6d commit 1737ba5

171 files changed

Lines changed: 1116 additions & 919 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

compiler/api/compiler.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,15 +328,16 @@ def start():
328328
)
329329

330330
if docstring_args:
331-
docstring_args = "Args:\n " + "\n ".join(docstring_args)
331+
docstring_args = "Parameters:\n " + "\n ".join(docstring_args)
332332
else:
333333
docstring_args = "No parameters required."
334334

335335
docstring_args = "Attributes:\n ID: ``{}``\n\n ".format(c.id) + docstring_args
336336

337337
if c.section == "functions":
338-
docstring_args += "\n\n Raises:\n :obj:`RPCError <pyrogram.RPCError>`"
339338
docstring_args += "\n\n Returns:\n " + get_docstring_arg_type(c.return_type)
339+
docstring_args += "\n\n Raises:\n RPCError: In case of a Telegram RPC error."
340+
340341
else:
341342
references = get_references(".".join(filter(None, [c.namespace, c.name])))
342343

docs/source/conf.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
'sphinx.ext.autosummary'
4545
]
4646

47+
napoleon_use_rtype = False
48+
4749
# Don't show source files on docs
4850
html_show_sourcelink = True
4951

@@ -112,7 +114,7 @@
112114
#
113115
html_theme_options = {
114116
'canonical_url': "https://docs.pyrogram.ml/",
115-
'collapse_navigation': False,
117+
'collapse_navigation': True,
116118
'sticky_navigation': False,
117119
'logo_only': True,
118120
'display_version': True

docs/source/pyrogram/Client.rst

Lines changed: 0 additions & 162 deletions
This file was deleted.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
Decorators
2+
==========
3+
4+
While still being methods bound to the :obj:`Client` class, decorators are of a special kind and thus deserve a
5+
dedicated page.
6+
7+
Decorators are able to register callback functions for handling updates in a much easier and cleaner way compared to
8+
`Handlers <Handlers.html>`_; they do so by instantiating the correct handler and calling
9+
:meth:`add_handler() <pyrogram.Client.add_handler>`, automatically. All you need to do is adding the decorators on top
10+
of your functions.
11+
12+
**Example:**
13+
14+
.. code-block:: python
15+
16+
from pyrogram import Client
17+
18+
app = Client(...)
19+
20+
21+
@app.on_message()
22+
def log(client, message):
23+
print(message)
24+
25+
26+
app.run()
27+
28+
.. currentmodule:: pyrogram.Client
29+
30+
.. autosummary::
31+
:nosignatures:
32+
33+
on_message
34+
on_callback_query
35+
on_inline_query
36+
on_deleted_messages
37+
on_user_status
38+
on_disconnect
39+
on_raw_update
40+
41+
.. automethod:: pyrogram.Client.on_message()
42+
.. automethod:: pyrogram.Client.on_callback_query()
43+
.. automethod:: pyrogram.Client.on_inline_query()
44+
.. automethod:: pyrogram.Client.on_deleted_messages()
45+
.. automethod:: pyrogram.Client.on_user_status()
46+
.. automethod:: pyrogram.Client.on_disconnect()
47+
.. automethod:: pyrogram.Client.on_raw_update()

docs/source/pyrogram/Errors.rst

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
Errors
2+
======
3+
4+
All the Pyrogram errors listed here live inside the ``errors`` sub-package.
5+
6+
**Example:**
7+
8+
.. code-block:: python
9+
10+
from pyrogram.errors import RPCError
11+
12+
try:
13+
...
14+
except RPCError:
15+
...
16+
17+
.. autoexception:: pyrogram.RPCError()
18+
:members:
19+
20+
.. toctree::
21+
../errors/SeeOther
22+
../errors/BadRequest
23+
../errors/Unauthorized
24+
../errors/Forbidden
25+
../errors/NotAcceptable
26+
../errors/Flood
27+
../errors/InternalServerError
28+
../errors/UnknownError

docs/source/pyrogram/Handlers.rst

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,29 @@
11
Handlers
22
========
33

4+
Handlers are used to instruct Pyrogram about which kind of updates you'd like to handle with your callback functions.
5+
6+
For a much more convenient way of registering callback functions have a look at `Decorators <Decorators.html>`_ instead.
7+
In case you decided to manually create an handler, use :meth:`add_handler() <pyrogram.Client.add_handler>` to register
8+
it.
9+
10+
**Example:**
11+
12+
.. code-block:: python
13+
14+
from pyrogram import Client, MessageHandler
15+
16+
app = Client(...)
17+
18+
19+
def dump(client, message):
20+
print(message)
21+
22+
23+
app.add_handler(MessageHandler(dump))
24+
25+
app.run()
26+
427
.. currentmodule:: pyrogram
528

629
.. autosummary::
@@ -14,24 +37,24 @@ Handlers
1437
DisconnectHandler
1538
RawUpdateHandler
1639

17-
.. autoclass:: MessageHandler
40+
.. autoclass:: MessageHandler()
1841
:members:
1942

20-
.. autoclass:: DeletedMessagesHandler
43+
.. autoclass:: DeletedMessagesHandler()
2144
:members:
2245

23-
.. autoclass:: CallbackQueryHandler
46+
.. autoclass:: CallbackQueryHandler()
2447
:members:
2548

26-
.. autoclass:: InlineQueryHandler
49+
.. autoclass:: InlineQueryHandler()
2750
:members:
2851

29-
.. autoclass:: UserStatusHandler
52+
.. autoclass:: UserStatusHandler()
3053
:members:
3154

32-
.. autoclass:: DisconnectHandler
55+
.. autoclass:: DisconnectHandler()
3356
:members:
3457

35-
.. autoclass:: RawUpdateHandler
58+
.. autoclass:: RawUpdateHandler()
3659
:members:
3760

0 commit comments

Comments
 (0)