mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2024-12-22 22:45:09 +01:00
Improve Insertion of Kwargs into Bot
Methods (#3965)
This commit is contained in:
parent
a0c81ec3d4
commit
6d2334c88b
2 changed files with 20 additions and 28 deletions
|
@ -18,42 +18,31 @@
|
||||||
import inspect
|
import inspect
|
||||||
|
|
||||||
keyword_args = [
|
keyword_args = [
|
||||||
|
"Keyword Arguments:",
|
||||||
(
|
(
|
||||||
":keyword _sphinx_paramlinks_telegram.Bot.{method}.read_timeout: Value to pass to "
|
" read_timeout ({read_timeout_type}, optional): Value to pass to "
|
||||||
":paramref:`telegram.request.BaseRequest.post.read_timeout`. Defaults to {read_timeout}."
|
" :paramref:`telegram.request.BaseRequest.post.read_timeout`. Defaults to "
|
||||||
),
|
" {read_timeout}."
|
||||||
":kwtype _sphinx_paramlinks_telegram.Bot.{method}.read_timeout: {read_timeout_type}, optional",
|
|
||||||
(
|
|
||||||
":keyword _sphinx_paramlinks_telegram.Bot.{method}.write_timeout: Value to pass to "
|
|
||||||
":paramref:`telegram.request.BaseRequest.post.write_timeout`. Defaults to {write_timeout}."
|
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
":kwtype _sphinx_paramlinks_telegram.Bot.{method}.write_timeout: :obj:`float` |"
|
" write_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to "
|
||||||
" :obj:`None`, optional"
|
" :paramref:`telegram.request.BaseRequest.post.write_timeout`. Defaults to "
|
||||||
|
" {write_timeout}."
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
":keyword _sphinx_paramlinks_telegram.Bot.{method}.connect_timeout: Value to pass to "
|
" connect_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to "
|
||||||
" :paramref:`telegram.request.BaseRequest.post.connect_timeout`. Defaults to "
|
" :paramref:`telegram.request.BaseRequest.post.connect_timeout`. Defaults to "
|
||||||
" :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`."
|
" :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`."
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
":kwtype _sphinx_paramlinks_telegram.Bot.{method}.connect_timeout: :obj:`float` | "
|
" pool_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to "
|
||||||
":obj:`None`, optional"
|
|
||||||
),
|
|
||||||
(
|
|
||||||
":keyword _sphinx_paramlinks_telegram.Bot.{method}.pool_timeout: Value to pass to "
|
|
||||||
" :paramref:`telegram.request.BaseRequest.post.pool_timeout`. Defaults to "
|
" :paramref:`telegram.request.BaseRequest.post.pool_timeout`. Defaults to "
|
||||||
" :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`."
|
" :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`."
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
":kwtype _sphinx_paramlinks_telegram.Bot.{method}.pool_timeout: :obj:`float` |"
|
" api_kwargs (:obj:`dict`, optional): Arbitrary keyword arguments"
|
||||||
" :obj:`None`, optional"
|
|
||||||
),
|
|
||||||
(
|
|
||||||
":keyword _sphinx_paramlinks_telegram.Bot.{method}.api_kwargs: Arbitrary keyword arguments"
|
|
||||||
" to be passed to the Telegram API."
|
" to be passed to the Telegram API."
|
||||||
),
|
),
|
||||||
":kwtype _sphinx_paramlinks_telegram.Bot.{method}.api_kwargs: :obj:`dict`, optional",
|
|
||||||
"",
|
"",
|
||||||
]
|
]
|
||||||
write_timeout_sub = [":attr:`~telegram.request.BaseRequest.DEFAULT_NONE`", "``20``"]
|
write_timeout_sub = [":attr:`~telegram.request.BaseRequest.DEFAULT_NONE`", "``20``"]
|
||||||
|
@ -67,7 +56,7 @@ read_timeout_type = [":obj:`float` | :obj:`None`", ":obj:`float`"]
|
||||||
def find_insert_pos_for_kwargs(lines: list[str]) -> int:
|
def find_insert_pos_for_kwargs(lines: list[str]) -> int:
|
||||||
"""Finds the correct position to insert the keyword arguments and returns the index."""
|
"""Finds the correct position to insert the keyword arguments and returns the index."""
|
||||||
for idx, value in reversed(list(enumerate(lines))): # reversed since :returns: is at the end
|
for idx, value in reversed(list(enumerate(lines))): # reversed since :returns: is at the end
|
||||||
if value.startswith(":returns:"):
|
if value.startswith("Returns"):
|
||||||
return idx
|
return idx
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
|
@ -320,5 +320,8 @@ from docs.auxil.tg_const_role import CONSTANTS_ROLE, TGConstXRefRole
|
||||||
def setup(app: Sphinx):
|
def setup(app: Sphinx):
|
||||||
app.connect("autodoc-skip-member", autodoc_skip_member)
|
app.connect("autodoc-skip-member", autodoc_skip_member)
|
||||||
app.connect("autodoc-process-bases", autodoc_process_bases)
|
app.connect("autodoc-process-bases", autodoc_process_bases)
|
||||||
app.connect("autodoc-process-docstring", autodoc_process_docstring)
|
# The default priority is 500. We want our function to run before napoleon doc-conversion
|
||||||
|
# and sphinx-paramlinks do, b/c otherwise the inserted kwargs in the bot methods won't show
|
||||||
|
# up in the objects.inv file that Sphinx generates (i.e. not in the search).
|
||||||
|
app.connect("autodoc-process-docstring", autodoc_process_docstring, priority=100)
|
||||||
app.add_role_to_domain("py", CONSTANTS_ROLE, TGConstXRefRole())
|
app.add_role_to_domain("py", CONSTANTS_ROLE, TGConstXRefRole())
|
||||||
|
|
Loading…
Reference in a new issue