Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a46325c
Fix: Improving the doc strings one dot at a time
Poolitzer May 7, 2026
96fd8a4
Merge branch 'master' into doc-fixes
harshil21 May 20, 2026
db5d839
Sequence -> tuple doc fix
harshil21 May 20, 2026
5e78628
Rename file without leading underscore
harshil21 May 20, 2026
a4cad41
Add chango fragment for PR #5240
harshil21 May 20, 2026
a6b1e32
Fix other imports
harshil21 May 20, 2026
f58ec82
Autogen Raises: block, fix kwargs and admonition insertion bug
harshil21 May 20, 2026
bae37b0
WIP: Start rewriting the doc autogenerator
harshil21 May 25, 2026
f862757
First pass on autogeneration of attrs
harshil21 May 26, 2026
3047777
Remove Attributes from docstrings wherever applicable
harshil21 May 26, 2026
2fa5119
raise error instead of a warning for unresolvable attrs
harshil21 May 26, 2026
a171534
Review: keyword args doc for do_api_request
harshil21 May 26, 2026
70d074e
Review: Update changelog
harshil21 May 26, 2026
d329049
Merge branch 'auto-doc-raises' into auto-doc-attr
harshil21 May 26, 2026
5388a66
Add missing poll option to toctree
harshil21 May 26, 2026
5dd9054
Merge branch 'doc-fixes' into auto-doc-raises
harshil21 May 26, 2026
5215441
Merge branch 'auto-doc-raises' into auto-doc-attr
harshil21 May 26, 2026
2a7e0b3
Fix missing Attributes, update changelog
harshil21 May 26, 2026
8cd9a8a
Update test workflow for docs
harshil21 May 26, 2026
0c7053c
Auto insert raises block, fix `Bot` kwargs insertion regression (#5241)
harshil21 May 26, 2026
19f1d4b
fix typo
harshil21 May 26, 2026
3c1c084
Merge doc-fixes and fix conflicts
harshil21 May 26, 2026
8b76d05
Merge doc-fixes and fix conflicts
harshil21 Jun 16, 2026
1daa65d
Review: minor optimization, clarify a few things
harshil21 Jun 16, 2026
b004cef
Add chango fragment for PR #5246
harshil21 Jun 16, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Auto insert raises block, fix Bot kwargs insertion regression (#5241)
  • Loading branch information
harshil21 authored May 26, 2026
commit 0c7053c8bdbda056e4f8e196a776ee7b0bd58a24
9 changes: 5 additions & 4 deletions changes/unreleased/5240.iJXyH8RNWNNQpC47SfNHzw.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
documentation = "Documentation Improvements"
[[pull_requests]]
uid = "5240"
author_uids = ["harshil21"]
closes_threads = []

pull_requests = [
{ uid = "5240", author_uids = ["harshil21", "Poolitzer"] },
{ uid = "5241", author_uids = ["harshil21"] },
]
14 changes: 14 additions & 0 deletions docs/auxil/kwargs_insertion.py → docs/auxil/bot_insertion.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@
" ``2``.",
]

RAISES_BLOCK = [
"Raises:",
"",
" :class:`telegram.error.TelegramError`",
"",
]


def find_insert_pos_for_kwargs(lines: list[str]) -> int:
"""Finds the correct position to insert the keyword arguments and returns the index."""
Expand All @@ -92,6 +99,13 @@ def find_insert_pos_for_kwargs(lines: list[str]) -> int:
return False


def find_insert_pos_for_raises(lines: list[str]) -> int:
"""Finds the correct position to insert the Raises block and returns the index."""
if "Raises:" in lines:
return -1 # Don't insert if there's already a Raises block
return len(lines) # Insert at the end if there's no Raises block


def check_timeout_and_api_kwargs_presence(obj: object) -> int:
Comment thread
harshil21 marked this conversation as resolved.
Outdated
"""Checks if the method has timeout and api_kwargs keyword only parameters."""
sig = inspect.signature(obj)
Expand Down
22 changes: 18 additions & 4 deletions docs/auxil/sphinx_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@
import telegram
import telegram.ext
from docs.auxil.admonition_inserter import AdmonitionInserter
from docs.auxil.kwargs_insertion import (
from docs.auxil.bot_insertion import (
RAISES_BLOCK,
check_timeout_and_api_kwargs_presence,
find_insert_pos_for_kwargs,
find_insert_pos_for_raises,
get_updates_read_timeout_addition,
keyword_args,
media_write_timeout_change,
Expand Down Expand Up @@ -84,8 +86,8 @@ def autodoc_process_docstring(
app: Sphinx, what, name: str, obj: object, options, lines: list[str]
):
"""We do the following things:
1) Use this method to automatically insert the Keyword Args and "Shortcuts" admonitions
for the Bot methods.
1) Use this method to automatically insert the Keyword Args, "Shortcuts" admonitions,
and the Raises block, wherever applicable, for the Bot methods.

Comment thread
harshil21 marked this conversation as resolved.
2) Use this method to automatically insert "Returned in" admonition into classes
that are returned from the Bot methods
Expand All @@ -101,13 +103,15 @@ def autodoc_process_docstring(
"""

# 1) Insert the Keyword Args and "Shortcuts" admonitions for the Bot methods
method_name = name.rsplit(".", maxsplit=1)[0]
method_name = name.rsplit(".", maxsplit=1)[-1]
if (
name.startswith("telegram.Bot.")
and what == "method"
and method_name.islower()
and check_timeout_and_api_kwargs_presence(obj)
):
Comment thread
harshil21 marked this conversation as resolved.
# Logic for inserting keyword args into docstrings:
# -------------------------------------------------
insert_index = find_insert_pos_for_kwargs(lines)
if not insert_index:
raise ValueError(
Expand All @@ -133,6 +137,16 @@ def autodoc_process_docstring(
lines[insert_idx:insert_idx] = effective_insert
insert_idx += len(effective_insert)

# Logic for inserting Raises:
# -------------------------------------------------
# We will only insert the Raises block if there isn't already one.

insert_index = find_insert_pos_for_raises(lines)
if insert_index != -1:
lines[insert_index:insert_index] = RAISES_BLOCK

# Logic for inserting "Shortcuts" admonition:
# -------------------------------------------
ADMONITION_INSERTER.insert_admonitions(
obj=typing.cast("collections.abc.Callable", obj),
docstring_lines=lines,
Expand Down
Loading
Loading