Skip to content

Commit a1f2d08

Browse files
SpEcHiDegemini-code-assist[bot]KurimuzonAkuma
authored
Improve documentation of various types (#230)
Closes #229 Co-authored-by: gemini-code-assist[bot] <176961590@users.noreply.github.com> Co-authored-by: KurimuzonAkuma <KurimuzonAkuma@users.noreply.github.com>
1 parent 53a6547 commit a1f2d08

File tree

86 files changed

+985
-374
lines changed

Some content is hidden

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

86 files changed

+985
-374
lines changed

.github/workflows/build-docs.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ jobs:
1111
name: build-doc
1212
runs-on: ubuntu-latest
1313
steps:
14-
- uses: actions/checkout@v4
14+
- uses: actions/checkout@v6
1515
with:
1616
fetch-depth: 1
1717
- name: Set up Python
18-
uses: actions/setup-python@v5
18+
uses: actions/setup-python@v6
1919
with:
20-
python-version: '3.10'
20+
python-version: "3.10"
2121

2222
- name: Install dependencies AND Build Documentation
2323
env:

docs/source/api/errors/index.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ follow the usual *PascalCase* convention.
3939
.. admonition :: RPC Errors
4040
:class: tip
4141
42-
There isn't any official list of all possible RPC errors, so the list of known errors is provided on a best-effort basis. When new methods are available, the list may be lacking since we simply don't know what errors can raise from them. Pyrogram creates an `unknown_errors.txt` file in the root directory from where the `Client` is run.
42+
There isn't any official list of all possible RPC errors, so the list of known errors is provided on a best-effort basis. When new methods are available, the list may be lacking since we simply don't know what errors can raise from them. Pyrogram creates an ``unknown_errors.txt`` file in the root directory from where the `Client` is run.
4343
4444
.. admonition :: PLEASE DO NOT DO THIS
4545
4646
.. tip::
4747
48-
If you do not want this file to be created, set the `PYROGRAM_DONOT_LOG_UNKNOWN_ERRORS` environment variable before running the Pyrogram `Client`.
48+
If you want the file to be created in a different location, set the ``PYROGRAM_LOG_UNKNOWN_ERRORS_FILENAME`` environment variable to an absolute file path of your choice.
4949
5050
.. tip::
5151
52-
If you want the file to be created in a different location, set the `PYROGRAM_LOG_UNKNOWN_ERRORS_FILENAME` to a file path of your choice.
52+
If you do not want this file to be created, set the ``PYROGRAM_DONOT_LOG_UNKNOWN_ERRORS`` environment variable before running the Pyrogram `Client`.

docs/source/conf.py

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
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+
import inspect
1920
import os
2021
import subprocess
2122
import sys
@@ -32,8 +33,11 @@
3233
"HEAD",
3334
]).decode("UTF-8").strip()
3435

36+
project_url = "https://github.com/TelegramPlayGround/Pyrogram"
37+
# --- SETUP: Define your repository root ---
38+
REPO_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))
3539
project = "pyrotgfork"
36-
copyright = "2017-present, Dan"
40+
copyright = "2017-2024, Dan"
3741
author = "Dan"
3842
version = f"{__version__} Layer {layer}"
3943

@@ -45,6 +49,7 @@
4549
# "sphinx.ext.viewcode",
4650
"sphinx_copybutton",
4751
# "sphinx.ext.coverage",
52+
"sphinx.ext.linkcode",
4853
"sphinx_llms_txt",
4954
]
5055

@@ -158,3 +163,57 @@
158163
"genindex",
159164
"modindex",
160165
]
166+
167+
def linkcode_resolve(domain, info):
168+
"""
169+
Determine the URL corresponding to Python object
170+
"""
171+
if domain != "py":
172+
return None
173+
if not info["module"]:
174+
return None
175+
176+
# Attempt to find the exact line numbers using the inspect module
177+
module = sys.modules.get(info["module"])
178+
if module is None:
179+
return None
180+
181+
# Traverse the object tree to find the specific class/function
182+
obj = module
183+
for part in info["fullname"].split("."):
184+
try:
185+
obj = getattr(obj, part)
186+
except AttributeError:
187+
return None
188+
189+
# --- Unwrap decorators to bypass sync.py wrappers ---
190+
try:
191+
obj = inspect.unwrap(obj)
192+
except:
193+
pass # If it can't be unwrapped, just proceed with the original object
194+
195+
try:
196+
# 1. Get the absolute path to the file locally
197+
filepath = inspect.getsourcefile(obj)
198+
if filepath is None:
199+
return None
200+
201+
# 2. Calculate the path relative to the root of your git repository
202+
rel_filepath = os.path.relpath(filepath, start=REPO_ROOT)
203+
204+
# Ensure forward slashes for the GitHub URL (important for Windows users)
205+
rel_filepath = rel_filepath.replace(os.sep, "/")
206+
207+
# 3. Get the line numbers
208+
source, lineno = inspect.getsourcelines(obj)
209+
210+
# Return the perfectly mapped GitHub URL
211+
# Returns a link like: https://github.com/user/repo/blob/main/module.py#L10-L25
212+
return f"{project_url}/blob/{commit_id}/{rel_filepath}#L{lineno}-L{lineno + len(source) - 1}"
213+
214+
except (TypeError, OSError, ValueError):
215+
# Fails safely if source cannot be inspected or path calculation fails
216+
return None
217+
218+
# Fallback to just linking to the file if line numbers can't be resolved
219+
return f"{project_url}/blob/{commit_id}/{filename}.py"

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

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11

2-
Changes in this Fork
3-
=====================
4-
52
.. admonition :: A Word of Warning
63
:class: tip
74
@@ -17,15 +14,15 @@ it can take advantage of new goodies!
1714

1815
If you found any issue or have any suggestions, feel free to make `an issue <https://github.com/TelegramPlayGround/pyrogram/issues>`__ on github.
1916

20-
Breaking Changes in this Fork
21-
==============================
17+
.. admonition :: Breaking Changes in this Fork
18+
:class: tip
2219
23-
- In :meth:`~pyrogram.Client.copy_message`, ``ValueError`` is raised instead of ``logging`` it.
24-
- In :meth:`~pyrogram.Client.download_media`, if the message is a :obj:`~pyrogram.types.PaidMediaInfo` with more than one ``paid_media`` **and** ``idx`` was not specified, then a list of paths or binary file-like objects is returned.
25-
- PR `#115 <https://github.com/TelegramPlayGround/pyrogram/pull/115>`_ This `change <https://github.com/pyrogram/pyrogram/pull/966#issuecomment-1108858881>`_ breaks some usages with offset-naive and offset-aware datetimes.
26-
- PR from upstream: `#1411 <https://github.com/pyrogram/pyrogram/pull/1411>`_ without attribution.
27-
- If you relied on internal types like ``import pyrogram.file_id`` OR ``import pyrogram.utils``, Then read this full document to know where `else <https://t.me/PyrogramChat/42497>`_ your code will break.
28-
- :obj:`~pyrogram.types.InlineKeyboardButton` only accepts keyword arguments instead of positional arguments.
20+
- In :meth:`~pyrogram.Client.copy_message`, ``ValueError`` is raised instead of ``logging`` it.
21+
- In :meth:`~pyrogram.Client.download_media`, if the message is a :obj:`~pyrogram.types.PaidMediaInfo` with more than one ``paid_media`` **and** ``idx`` was not specified, then a list of paths or binary file-like objects is returned.
22+
- PR `#115 <https://github.com/TelegramPlayGround/pyrogram/pull/115>`_ This `change <https://github.com/pyrogram/pyrogram/pull/966#issuecomment-1108858881>`_ breaks some usages with offset-naive and offset-aware datetimes.
23+
- PR from upstream: `#1411 <https://github.com/pyrogram/pyrogram/pull/1411>`_ without attribution.
24+
- If you relied on internal types like ``import pyrogram.file_id`` OR ``import pyrogram.utils``, Then read this full document to know where `else <https://t.me/PyrogramChat/42497>`_ your code will break.
25+
- :obj:`~pyrogram.types.InlineKeyboardButton` only accepts keyword arguments instead of positional arguments.
2926
3027
3128
Changes in this Fork
@@ -55,6 +52,7 @@ Changes in this Fork
5552
| Scheme layer used: 223 |
5653
+------------------------+
5754

55+
- Added the method :meth:`~pyrogram.Client.send_message_draft`, allowing bots to stream partial messages to a user while being generated. (contributed by @sudo-py-dev in `#231 <https://github.com/TelegramPlayground/pyrogram/pull/231>`__).
5856
- Added the :obj:`~pyrogram.types.MessageEntity` type :obj:`~pyrogram.enums.MessageEntityType.DATE_TIME`, allowing to show a formatted date and time to the user.
5957
- Added the fields ``chat_owner_left``, ``chat_owner_changed``, ``chat_has_protected_content_toggled`` and ``chat_has_protected_content_disable_requested`` to the class :obj:`~pyrogram.types.Message`.
6058
- Added the field ``can_edit_tag`` to the class :obj:`~pyrogram.types.ChatPermissions`.

docs/source/start/errors.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,11 @@ whole category of errors and be sure to also handle these unknown errors.
8080
.. admonition :: RPC Errors
8181
:class: tip
8282
83-
There isn't any official list of all possible RPC errors, so the list of known errors is provided on a best-effort basis. When new methods are available, the list may be lacking since we simply don't know what errors can raise from them. Pyrogram creates an `unknown_errors.txt` file in the root directory from where the `Client` is run.
83+
There isn't any official list of all possible RPC errors, so the list of known errors is provided on a best-effort basis. When new methods are available, the list may be lacking since we simply don't know what errors can raise from them. Pyrogram creates an ``unknown_errors.txt`` file in the root directory from where the `Client` is run.
8484
8585
.. admonition :: `... <https://t.me/pyrogramchat/607757>`__
8686
87-
If you want the file to be created in a different location, set the ``PYROGRAM_LOG_UNKNOWN_ERRORS_FILENAME`` to an absolute file path of your choice.
87+
If you want the file to be created in a different location, set the ``PYROGRAM_LOG_UNKNOWN_ERRORS_FILENAME`` environment variable to an absolute file path of your choice.
8888
8989
9090
Errors with Values

docs/source/topics/message-identifiers.rst

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,9 @@ Let's look at a concrete example.
4040
Every account and channel has just been created.
4141
This means everyone has a message counter of one.
4242

43-
First, User-A will sent a welcome message to both User-B and User-C::
43+
.. First, User-A will sent a welcome message to both User-B and User-C::
4444
45-
..
4645
User-A → User-B: Hey, welcome!
47-
4846
User-A → User-C: ¡Bienvenido!
4947
5048
* For User-A, "Hey, welcome!" will have the message identifier 1. The message with "¡Bienvenido!" will have an ID of 2.
@@ -57,11 +55,10 @@ First, User-A will sent a welcome message to both User-B and User-C::
5755
"Hey, welcome!", 1, 1, "", "", ""
5856
"¡Bienvenido!", 2, "", 1, "", ""
5957

60-
Next, User-B and User-C will respond to User-A::
6158

62-
..
63-
User-B → User-A: Thanks!
59+
.. Next, User-B and User-C will respond to User-A::
6460
61+
User-B → User-A: Thanks!
6562
User-C → User-A: Gracias :)
6663
6764
.. csv-table:: Message identifiers
@@ -74,9 +71,8 @@ Next, User-B and User-C will respond to User-A::
7471

7572
Notice how for each message, the counter goes up by one, and they are independent.
7673

77-
Let's see what happens when User-B sends a message to Group-S::
74+
.. Let's see what happens when User-B sends a message to Group-S::
7875
79-
..
8076
User-B → Group-S: Nice group
8177
8278
.. csv-table:: Message identifiers
@@ -92,9 +88,7 @@ While the message was sent to a different chat, the group itself doesn't have a
9288
The message identifiers are still unique for each account.
9389
The chat where the message was sent can be completely ignored.
9490

95-
Megagroups behave differently::
96-
97-
..
91+
.. Megagroups behave differently::
9892
User-C → Group-M: Buen grupo
9993
10094
.. csv-table:: Message identifiers

docs/source/topics/text-formatting.rst

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,12 @@ To strictly use this mode, pass :obj:`~pyrogram.enums.ParseMode.MARKDOWN` to the
160160
>Block quotation continued
161161
>The last line of the block quotation
162162
163-
**>
164-
The expandable block quotation started right after the previous block quotation
165-
It is separated from the previous block quotation by expandable syntax
166-
Expandable block quotation continued
167-
Hidden by default part of the expandable block quotation started
168-
Expandable block quotation continued
169-
The last line of the expandable block quotation with the expandability mark<**
163+
**>The expandable block quotation started right after the previous block quotation
164+
>It is separated from the previous block quotation by expandable syntax
165+
>Expandable block quotation continued
166+
>Hidden by default part of the expandable block quotation started
167+
>Expandable block quotation continued
168+
>The last line of the expandable block quotation with the expandability mark||
170169
171170
`inline fixed-width code`
172171
@@ -215,13 +214,12 @@ To strictly use this mode, pass :obj:`~pyrogram.enums.ParseMode.MARKDOWN` to the
215214
">Block quotation continued\n"
216215
">The last line of the block quotation"
217216
218-
"**>\n"
219-
"The expandable block quotation started right after the previous block quotation\n"
220-
"It is separated from the previous block quotation by expandable syntax\n"
221-
"Expandable block quotation continued\n"
222-
"Hidden by default part of the expandable block quotation started\n"
223-
"Expandable block quotation continued\n"
224-
"The last line of the expandable block quotation with the expandability mark<**"
217+
"**>The expandable block quotation started right after the previous block quotation\n"
218+
">It is separated from the previous block quotation by expandable syntax\n"
219+
">Expandable block quotation continued\n"
220+
">Hidden by default part of the expandable block quotation started\n"
221+
">Expandable block quotation continued\n"
222+
">The last line of the expandable block quotation with the expandability mark||"
225223
226224
),
227225
parse_mode=ParseMode.MARKDOWN

pyrogram/file_id.py

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -307,25 +307,25 @@ class FileIdCached:
307307
_encoded: typing.Optional[str] = None
308308

309309
def __init__(
310-
self, *,
311-
major: int = MAJOR,
312-
minor: int = MINOR,
313-
file_type: FileType,
314-
dc_id: int,
315-
file_reference: bytes = b"",
316-
url: str = None,
317-
media_id: int = None,
318-
access_hash: int = None,
319-
volume_id: int = None,
320-
thumbnail_source: ThumbnailSource = None,
321-
thumbnail_file_type: FileType = None,
322-
thumbnail_size: str = "",
323-
secret: int = None,
324-
local_id: int = None,
325-
chat_id: int = None,
326-
chat_access_hash: int = None,
327-
sticker_set_id: int = None,
328-
sticker_set_access_hash: int = None
310+
self, *,
311+
major: int = MAJOR,
312+
minor: int = MINOR,
313+
file_type: FileType,
314+
dc_id: int,
315+
file_reference: bytes = b"",
316+
url: str = None,
317+
media_id: int = None,
318+
access_hash: int = None,
319+
volume_id: int = None,
320+
thumbnail_source: ThumbnailSource = None,
321+
thumbnail_file_type: FileType = None,
322+
thumbnail_size: str = "",
323+
secret: int = None,
324+
local_id: int = None,
325+
chat_id: int = None,
326+
chat_access_hash: int = None,
327+
sticker_set_id: int = None,
328+
sticker_set_access_hash: int = None
329329
):
330330
self.major = major
331331
self.minor = minor
@@ -416,7 +416,7 @@ def encode(self, *, major: int = None, minor: int = None):
416416
return self._encoded
417417

418418
def __str__(self):
419-
return str({k: v for k, v in self.__dict__.items() if v is not None})
419+
return str({k: v for k, v in self.__dict__.items() if k != "_encoded" and v is not None})
420420

421421

422422
class FileUniqueType(IntEnum):
@@ -477,12 +477,12 @@ class FileUniqueIdCached:
477477
_encoded: typing.Optional[str] = None
478478

479479
def __init__(
480-
self, *,
481-
file_unique_type: FileUniqueType,
482-
url: str = None,
483-
media_id: int = None,
484-
volume_id: int = None,
485-
local_id: int = None
480+
self, *,
481+
file_unique_type: FileUniqueType,
482+
url: str = None,
483+
media_id: int = None,
484+
volume_id: int = None,
485+
local_id: int = None
486486
):
487487
self.file_unique_type = file_unique_type
488488
self.url = url
@@ -513,4 +513,4 @@ def encode(self):
513513
return self._encoded
514514

515515
def __str__(self):
516-
return str({k: v for k, v in self.__dict__.items() if v is not None})
516+
return str({k: v for k, v in self.__dict__.items() if k != "_encoded" and v is not None})

pyrogram/methods/advanced/invoke.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ async def invoke(
6868
``RawType``: The raw type response generated by the query.
6969
7070
Raises:
71-
RPCError: In case of a Telegram RPC error.
71+
:obj:`~pyrogram.errors.RPCError`: In case of a Telegram RPC error.
72+
7273
"""
7374
if not self.is_connected:
7475
raise ConnectionError("Client has not been started yet")

pyrogram/methods/advanced/resolve_peer.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ async def resolve_peer(
5353
5454
Raises:
5555
KeyError: In case the peer doesn't exist in the internal database.
56+
5657
"""
5758
if not self.is_connected:
5859
raise ConnectionError("Client has not been started yet")

0 commit comments

Comments
 (0)