mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2024-11-21 14:46:29 +01:00
One-Time Code Formatting Improvement via --preview
Flag of black
(#3882)
This commit is contained in:
parent
5b0f1697f1
commit
ab90cd7359
19 changed files with 220 additions and 159 deletions
|
@ -194,7 +194,7 @@ class AdmonitionInserter:
|
|||
)
|
||||
except NotImplementedError as e:
|
||||
raise NotImplementedError(
|
||||
f"Error generating Sphinx 'Available in' admonition "
|
||||
"Error generating Sphinx 'Available in' admonition "
|
||||
f"(admonition_inserter.py). Class {name_of_class_in_attr} present in "
|
||||
f"attribute {target_attr} of class {name_of_inspected_class_in_docstr}"
|
||||
f" could not be resolved. {str(e)}"
|
||||
|
@ -237,7 +237,7 @@ class AdmonitionInserter:
|
|||
)
|
||||
except NotImplementedError as e:
|
||||
raise NotImplementedError(
|
||||
f"Error generating Sphinx 'Available in' admonition "
|
||||
"Error generating Sphinx 'Available in' admonition "
|
||||
f"(admonition_inserter.py). Class {name_of_class_in_prop} present in "
|
||||
f"property {prop_name} of class {name_of_inspected_class_in_docstr}"
|
||||
f" could not be resolved. {str(e)}"
|
||||
|
@ -269,7 +269,7 @@ class AdmonitionInserter:
|
|||
)
|
||||
except NotImplementedError as e:
|
||||
raise NotImplementedError(
|
||||
f"Error generating Sphinx 'Returned in' admonition "
|
||||
"Error generating Sphinx 'Returned in' admonition "
|
||||
f"(admonition_inserter.py). {cls}, method {method_name}. "
|
||||
f"Couldn't resolve type hint in return annotation {ret_annot}. {str(e)}"
|
||||
)
|
||||
|
@ -342,7 +342,7 @@ class AdmonitionInserter:
|
|||
)
|
||||
except NotImplementedError as e:
|
||||
raise NotImplementedError(
|
||||
f"Error generating Sphinx 'Use in' admonition "
|
||||
"Error generating Sphinx 'Use in' admonition "
|
||||
f"(admonition_inserter.py). {cls}, method {method_name}, parameter "
|
||||
f"{param}: Couldn't resolve type hint {param.annotation}. {str(e)}"
|
||||
)
|
||||
|
|
|
@ -18,25 +18,41 @@
|
|||
import inspect
|
||||
|
||||
keyword_args = [
|
||||
":keyword _sphinx_paramlinks_telegram.Bot.{method}.read_timeout: Value to pass to "
|
||||
":paramref:`telegram.request.BaseRequest.post.read_timeout`. Defaults to {read_timeout}.",
|
||||
(
|
||||
":keyword _sphinx_paramlinks_telegram.Bot.{method}.read_timeout: Value to pass to "
|
||||
":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` | :obj:`None`, "
|
||||
"optional",
|
||||
":keyword _sphinx_paramlinks_telegram.Bot.{method}.connect_timeout: Value to pass to "
|
||||
":paramref:`telegram.request.BaseRequest.post.connect_timeout`. Defaults to "
|
||||
":attr:`~telegram.request.BaseRequest.DEFAULT_NONE`.",
|
||||
":kwtype _sphinx_paramlinks_telegram.Bot.{method}.connect_timeout: :obj:`float` | "
|
||||
":obj:`None`, optional",
|
||||
":keyword _sphinx_paramlinks_telegram.Bot.{method}.pool_timeout: Value to pass to "
|
||||
":paramref:`telegram.request.BaseRequest.post.pool_timeout`. Defaults to "
|
||||
":attr:`~telegram.request.BaseRequest.DEFAULT_NONE`.",
|
||||
":kwtype _sphinx_paramlinks_telegram.Bot.{method}.pool_timeout: :obj:`float` | :obj:`None`, "
|
||||
"optional",
|
||||
":keyword _sphinx_paramlinks_telegram.Bot.{method}.api_kwargs: Arbitrary keyword arguments "
|
||||
"to be passed to the Telegram API.",
|
||||
(
|
||||
":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` |"
|
||||
" :obj:`None`, optional"
|
||||
),
|
||||
(
|
||||
":keyword _sphinx_paramlinks_telegram.Bot.{method}.connect_timeout: Value to pass to "
|
||||
":paramref:`telegram.request.BaseRequest.post.connect_timeout`. Defaults to "
|
||||
":attr:`~telegram.request.BaseRequest.DEFAULT_NONE`."
|
||||
),
|
||||
(
|
||||
":kwtype _sphinx_paramlinks_telegram.Bot.{method}.connect_timeout: :obj:`float` | "
|
||||
":obj:`None`, optional"
|
||||
),
|
||||
(
|
||||
":keyword _sphinx_paramlinks_telegram.Bot.{method}.pool_timeout: Value to pass to "
|
||||
":paramref:`telegram.request.BaseRequest.post.pool_timeout`. Defaults to "
|
||||
":attr:`~telegram.request.BaseRequest.DEFAULT_NONE`."
|
||||
),
|
||||
(
|
||||
":kwtype _sphinx_paramlinks_telegram.Bot.{method}.pool_timeout: :obj:`float` |"
|
||||
" :obj:`None`, optional"
|
||||
),
|
||||
(
|
||||
":keyword _sphinx_paramlinks_telegram.Bot.{method}.api_kwargs: Arbitrary keyword arguments"
|
||||
" to be passed to the Telegram API."
|
||||
),
|
||||
":kwtype _sphinx_paramlinks_telegram.Bot.{method}.api_kwargs: :obj:`dict`, optional",
|
||||
"",
|
||||
]
|
||||
|
|
|
@ -96,7 +96,9 @@ linkcheck_ignore = [
|
|||
]
|
||||
linkcheck_allowed_redirects = {
|
||||
# Redirects to the default version are okay
|
||||
r"https://docs\.python-telegram-bot\.org/.*": r"https://docs\.python-telegram-bot\.org/en/[\w\d\.]+/.*",
|
||||
r"https://docs\.python-telegram-bot\.org/.*": (
|
||||
r"https://docs\.python-telegram-bot\.org/en/[\w\d\.]+/.*"
|
||||
),
|
||||
# pre-commit.ci always redirects to the latest run
|
||||
re.escape(
|
||||
"https://results.pre-commit.ci/latest/github/python-telegram-bot/python-telegram-bot/master"
|
||||
|
@ -131,71 +133,79 @@ html_theme_options = {
|
|||
"admonition-title-font-size": "0.95rem",
|
||||
"admonition-font-size": "0.92rem",
|
||||
},
|
||||
"announcement": "PTB has undergone significant changes in v20. Please read the documentation "
|
||||
"carefully and also check out the transition guide in the "
|
||||
'<a href="https://github.com/python-telegram-bot/python-telegram-bot/wiki/'
|
||||
'Transition-guide-to-Version-20.0">wiki</a>.',
|
||||
"announcement": (
|
||||
"PTB has undergone significant changes in v20. Please read the documentation "
|
||||
"carefully and also check out the transition guide in the "
|
||||
'<a href="https://github.com/python-telegram-bot/python-telegram-bot/wiki/'
|
||||
'Transition-guide-to-Version-20.0">wiki</a>.'
|
||||
),
|
||||
"footer_icons": [
|
||||
{
|
||||
# Telegram channel logo
|
||||
"name": "Telegram Channel",
|
||||
"url": "https://t.me/pythontelegrambotchannel/",
|
||||
# Following svg is from https://react-icons.github.io/react-icons/search?q=telegram
|
||||
"html": '<svg stroke="currentColor" fill="currentColor" stroke-width="0" '
|
||||
'viewBox="0 0 16 16" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg">'
|
||||
'<path d="M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0zM8.287 5.906c-.778.324-2.334.994'
|
||||
"-4.666 2.01-.378.15-.577.298-.595.442-.03.243.275.339.69.47l.175.055c.408.133."
|
||||
"958.288 1.243.294.26.006.549-.1.868-.32 2.179-1.471 3.304-2.214 3.374-2.23.0"
|
||||
"5-.012.12-.026.166.016.047.041.042.12.037.141-.03.129-1.227 1.241-1.846 1.81"
|
||||
"7-.193.18-.33.307-.358.336a8.154 8.154 0 0 1-.188.186c-.38.366-.664.64.015 1.08"
|
||||
"8.327.216.589.393.85.571.284.194.568.387.936.629.093.06.183.125.27.187.331.23"
|
||||
"6.63.448.997.414.214-.02.435-.22.547-.82.265-1.417.786-4.486.906-5.751a1.426 "
|
||||
"1.426 0 0 0-.013-.315.337.337 0 0 0-.114-.217.526.526 0 0 0-.31-.093c-.3.005-.7"
|
||||
'63.166-2.984 1.09z"></path></svg>',
|
||||
"html": (
|
||||
'<svg stroke="currentColor" fill="currentColor" stroke-width="0" '
|
||||
'viewBox="0 0 16 16" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg">'
|
||||
'<path d="M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0zM8.287 5.906c-.778.324-2.334.994'
|
||||
"-4.666 2.01-.378.15-.577.298-.595.442-.03.243.275.339.69.47l.175.055c.408.133."
|
||||
"958.288 1.243.294.26.006.549-.1.868-.32 2.179-1.471 3.304-2.214 3.374-2.23.0"
|
||||
"5-.012.12-.026.166.016.047.041.042.12.037.141-.03.129-1.227 1.241-1.846 1.81"
|
||||
"7-.193.18-.33.307-.358.336a8.154 8.154 0 0 1-.188.186c-.38.366-.664.64.015 1.08"
|
||||
"8.327.216.589.393.85.571.284.194.568.387.936.629.093.06.183.125.27.187.331.23"
|
||||
"6.63.448.997.414.214-.02.435-.22.547-.82.265-1.417.786-4.486.906-5.751a1.426 "
|
||||
"1.426 0 0 0-.013-.315.337.337 0 0 0-.114-.217.526.526 0 0 0-.31-.093c-.3.005-.7"
|
||||
'63.166-2.984 1.09z"></path></svg>'
|
||||
),
|
||||
"class": "",
|
||||
},
|
||||
{ # Github logo
|
||||
"name": "GitHub",
|
||||
"url": "https://github.com/python-telegram-bot/python-telegram-bot/",
|
||||
"html": '<svg stroke="currentColor" fill="currentColor" stroke-width="0" '
|
||||
'viewBox="0 0 16 16"><path fill-rule="evenodd" d="M8 0C3.58 0 0 3.58 0 8c0 3.54 '
|
||||
"2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.4"
|
||||
"9-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23"
|
||||
".82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 "
|
||||
"0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.2"
|
||||
"7 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.5"
|
||||
"1.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 "
|
||||
'1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0 0 16 8c0-4.42-3.58-8-8-8z">'
|
||||
"</path></svg>",
|
||||
"html": (
|
||||
'<svg stroke="currentColor" fill="currentColor" stroke-width="0" '
|
||||
'viewBox="0 0 16 16"><path fill-rule="evenodd" d="M8 0C3.58 0 0 3.58 0 8c0 3.54 '
|
||||
"2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.4"
|
||||
"9-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23"
|
||||
".82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 "
|
||||
"0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.2"
|
||||
"7 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.5"
|
||||
"1.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 "
|
||||
'1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0 0 16 8c0-4.42-3.58-8-8-8z">'
|
||||
"</path></svg>"
|
||||
),
|
||||
"class": "",
|
||||
},
|
||||
{ # PTB website logo - globe
|
||||
"name": "python-telegram-bot website",
|
||||
"url": "https://python-telegram-bot.org/",
|
||||
"html": '<svg stroke="currentColor" fill="currentColor" stroke-width="0" '
|
||||
'viewBox="0 0 16 16" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg">'
|
||||
'<path d="M0 8a8 8 0 1 1 16 0A8 8 0 0 1 0 8zm7.5-6.923c-.67.204-1.335.82-1.887 '
|
||||
"1.855-.143.268-.276.56-.395.872.705.157 1.472.257 2.282.287V1.077zM4.249 3.53"
|
||||
"9c.142-.384.304-.744.481-1.078a6.7 6.7 0 0 1 .597-.933A7.01 7.01 0 0 0 3.051 "
|
||||
"3.05c.362.184.763.349 1.198.49zM3.509 7.5c.036-1.07.188-2.087.436-3.008a9.124 "
|
||||
"9.124 0 0 1-1.565-.667A6.964 6.964 0 0 0 1.018 7.5h2.49zm1.4-2.741a12.344 "
|
||||
"12.344 0 0 0-.4 2.741H7.5V5.091c-.91-.03-1.783-.145-2.591-.332zM8.5 5.09V7.5h"
|
||||
"2.99a12.342 12.342 0 0 0-.399-2.741c-.808.187-1.681.301-2.591.332zM4.51 8.5c.03"
|
||||
"5.987.176 1.914.399 2.741A13.612 13.612 0 0 1 7.5 10.91V8.5H4.51zm3.99 0v2.409"
|
||||
"c.91.03 1.783.145 2.591.332.223-.827.364-1.754.4-2.741H8.5zm-3.282 3.696c.12.31"
|
||||
"2.252.604.395.872.552 1.035 1.218 1.65 1.887 1.855V11.91c-.81.03-1.577.13-2.28"
|
||||
"2.287zm.11 2.276a6.696 6.696 0 0 1-.598-.933 8.853 8.853 0 0 1-.481-1.079 8.38 "
|
||||
"8.38 0 0 0-1.198.49 7.01 7.01 0 0 0 2.276 1.522zm-1.383-2.964A13.36 13.36 0 0 1"
|
||||
" 3.508 8.5h-2.49a6.963 6.963 0 0 0 1.362 3.675c.47-.258.995-.482 1.565-.667zm"
|
||||
"6.728 2.964a7.009 7.009 0 0 0 2.275-1.521 8.376 8.376 0 0 0-1.197-.49 8.853 "
|
||||
"8.853 0 0 1-.481 1.078 6.688 6.688 0 0 1-.597.933zM8.5 11.909v3.014c.67-.204 "
|
||||
"1.335-.82 1.887-1.855.143-.268.276-.56.395-.872A12.63 12.63 0 0 0 8.5 11.91zm"
|
||||
"3.555-.401c.57.185 1.095.409 1.565.667A6.963 6.963 0 0 0 14.982 8.5h-2.49a1"
|
||||
"3.36 13.36 0 0 1-.437 3.008zM14.982 7.5a6.963 6.963 0 0 0-1.362-3.675c-.47.25"
|
||||
"8-.995.482-1.565.667.248.92.4 1.938.437 3.008h2.49zM11.27 2.461c.177.334.339.6"
|
||||
"94.482 1.078a8.368 8.368 0 0 0 1.196-.49 7.01 7.01 0 0 0-2.275-1.52c.218.283.4"
|
||||
"18.597.597.932zm-.488 1.343a7.765 7.765 0 0 0-.395-.872C9.835 1.897 9.17 1.282 "
|
||||
'8.5 1.077V4.09c.81-.03 1.577-.13 2.282-.287z"></path></svg>',
|
||||
"html": (
|
||||
'<svg stroke="currentColor" fill="currentColor" stroke-width="0" '
|
||||
'viewBox="0 0 16 16" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg">'
|
||||
'<path d="M0 8a8 8 0 1 1 16 0A8 8 0 0 1 0 8zm7.5-6.923c-.67.204-1.335.82-1.887 '
|
||||
"1.855-.143.268-.276.56-.395.872.705.157 1.472.257 2.282.287V1.077zM4.249 3.53"
|
||||
"9c.142-.384.304-.744.481-1.078a6.7 6.7 0 0 1 .597-.933A7.01 7.01 0 0 0 3.051 "
|
||||
"3.05c.362.184.763.349 1.198.49zM3.509 7.5c.036-1.07.188-2.087.436-3.008a9.124 "
|
||||
"9.124 0 0 1-1.565-.667A6.964 6.964 0 0 0 1.018 7.5h2.49zm1.4-2.741a12.344 "
|
||||
"12.344 0 0 0-.4 2.741H7.5V5.091c-.91-.03-1.783-.145-2.591-.332zM8.5 5.09V7.5h"
|
||||
"2.99a12.342 12.342 0 0 0-.399-2.741c-.808.187-1.681.301-2.591.332zM4.51 8.5c.03"
|
||||
"5.987.176 1.914.399 2.741A13.612 13.612 0 0 1 7.5 10.91V8.5H4.51zm3.99 0v2.409"
|
||||
"c.91.03 1.783.145 2.591.332.223-.827.364-1.754.4-2.741H8.5zm-3.282 3.696c.12.31"
|
||||
"2.252.604.395.872.552 1.035 1.218 1.65 1.887 1.855V11.91c-.81.03-1.577.13-2.28"
|
||||
"2.287zm.11 2.276a6.696 6.696 0 0 1-.598-.933 8.853 8.853 0 0 1-.481-1.079 8.38 "
|
||||
"8.38 0 0 0-1.198.49 7.01 7.01 0 0 0 2.276 1.522zm-1.383-2.964A13.36 13.36 0 0 1"
|
||||
" 3.508 8.5h-2.49a6.963 6.963 0 0 0 1.362 3.675c.47-.258.995-.482 1.565-.667zm"
|
||||
"6.728 2.964a7.009 7.009 0 0 0 2.275-1.521 8.376 8.376 0 0 0-1.197-.49 8.853 "
|
||||
"8.853 0 0 1-.481 1.078 6.688 6.688 0 0 1-.597.933zM8.5 11.909v3.014c.67-.204 "
|
||||
"1.335-.82 1.887-1.855.143-.268.276-.56.395-.872A12.63 12.63 0 0 0 8.5 11.91zm"
|
||||
"3.555-.401c.57.185 1.095.409 1.565.667A6.963 6.963 0 0 0 14.982 8.5h-2.49a1"
|
||||
"3.36 13.36 0 0 1-.437 3.008zM14.982 7.5a6.963 6.963 0 0 0-1.362-3.675c-.47.25"
|
||||
"8-.995.482-1.565.667.248.92.4 1.938.437 3.008h2.49zM11.27 2.461c.177.334.339.6"
|
||||
"94.482 1.078a8.368 8.368 0 0 0 1.196-.49 7.01 7.01 0 0 0-2.275-1.52c.218.283.4"
|
||||
"18.597.597.932zm-.488 1.343a7.765 7.765 0 0 0-.395-.872C9.835 1.897 9.17 1.282 "
|
||||
'8.5 1.077V4.09c.81-.03 1.577-.13 2.282-.287z"></path></svg>'
|
||||
),
|
||||
"class": "",
|
||||
},
|
||||
],
|
||||
|
|
|
@ -115,8 +115,7 @@ async def count_click(update: Update, context: CustomContext) -> None:
|
|||
async def print_users(update: Update, context: CustomContext) -> None:
|
||||
"""Show which users have been using this bot."""
|
||||
await update.message.reply_text(
|
||||
"The following user IDs have used this bot: "
|
||||
f'{", ".join(map(str, context.bot_user_ids))}'
|
||||
f"The following user IDs have used this bot: {', '.join(map(str, context.bot_user_ids))}"
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -57,8 +57,7 @@ async def deep_linked_level_1(update: Update, context: ContextTypes.DEFAULT_TYPE
|
|||
bot = context.bot
|
||||
url = helpers.create_deep_linked_url(bot.username, SO_COOL)
|
||||
text = (
|
||||
"Awesome, you just accessed hidden functionality! "
|
||||
"Now let's get back to the private chat."
|
||||
"Awesome, you just accessed hidden functionality! Now let's get back to the private chat."
|
||||
)
|
||||
keyboard = InlineKeyboardMarkup.from_button(
|
||||
InlineKeyboardButton(text="Continue here!", url=url)
|
||||
|
|
|
@ -40,7 +40,7 @@ async def error_handler(update: object, context: ContextTypes.DEFAULT_TYPE) -> N
|
|||
# You might need to add some logic to deal with messages longer than the 4096 character limit.
|
||||
update_str = update.to_dict() if isinstance(update, Update) else str(update)
|
||||
message = (
|
||||
f"An exception was raised while handling an update\n"
|
||||
"An exception was raised while handling an update\n"
|
||||
f"<pre>update = {html.escape(json.dumps(update_str, indent=2, ensure_ascii=False))}"
|
||||
"</pre>\n\n"
|
||||
f"<pre>context.chat_data = {html.escape(str(context.chat_data))}</pre>\n\n"
|
||||
|
|
|
@ -59,7 +59,7 @@ async def start(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int:
|
|||
if context.user_data:
|
||||
reply_text += (
|
||||
f" You already told me your {', '.join(context.user_data.keys())}. Why don't you "
|
||||
f"tell me something more about yourself? Or change anything I already know."
|
||||
"tell me something more about yourself? Or change anything I already know."
|
||||
)
|
||||
else:
|
||||
reply_text += (
|
||||
|
|
|
@ -45,8 +45,10 @@ async def web_app_data(update: Update, context: ContextTypes.DEFAULT_TYPE) -> No
|
|||
# (see webappbot.html)
|
||||
data = json.loads(update.effective_message.web_app_data.data)
|
||||
await update.message.reply_html(
|
||||
text=f"You selected the color with the HEX value <code>{data['hex']}</code>. The "
|
||||
f"corresponding RGB value is <code>{tuple(data['rgb'].values())}</code>.",
|
||||
text=(
|
||||
f"You selected the color with the HEX value <code>{data['hex']}</code>. The "
|
||||
f"corresponding RGB value is <code>{tuple(data['rgb'].values())}</code>."
|
||||
),
|
||||
reply_markup=ReplyKeyboardRemove(),
|
||||
)
|
||||
|
||||
|
|
|
@ -291,8 +291,8 @@ class Bot(TelegramObject, AsyncContextManager["Bot"]):
|
|||
if warning_string:
|
||||
self._warn(
|
||||
f"You set the HTTP version for the {warning_string} HTTPXRequest instance to "
|
||||
f"HTTP/2. The self hosted bot api instances only support HTTP/1.1. You should "
|
||||
f"either run a HTTP proxy in front of it which supports HTTP/2 or use HTTP/1.1.",
|
||||
"HTTP/2. The self hosted bot api instances only support HTTP/1.1. You should "
|
||||
"either run a HTTP proxy in front of it which supports HTTP/2 or use HTTP/1.1.",
|
||||
PTBUserWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
|
|
|
@ -948,7 +948,7 @@ class Application(Generic[BT, CCT, UD, CD, BD, JQ], AsyncContextManager["Applica
|
|||
warn(
|
||||
f"Could not add signal handlers for the stop signals {stop_signals} due to "
|
||||
f"exception `{exc!r}`. If your event loop does not implement `add_signal_handler`,"
|
||||
f" please pass `stop_signals=None`.",
|
||||
" please pass `stop_signals=None`.",
|
||||
stacklevel=3,
|
||||
)
|
||||
|
||||
|
@ -1080,8 +1080,7 @@ class Application(Generic[BT, CCT, UD, CD, BD, JQ], AsyncContextManager["Applica
|
|||
except Exception as exception:
|
||||
if isinstance(exception, ApplicationHandlerStop):
|
||||
warn(
|
||||
"ApplicationHandlerStop is not supported with handlers "
|
||||
"running non-blocking.",
|
||||
"ApplicationHandlerStop is not supported with handlers running non-blocking.",
|
||||
stacklevel=1,
|
||||
)
|
||||
|
||||
|
@ -1186,8 +1185,10 @@ class Application(Generic[BT, CCT, UD, CD, BD, JQ], AsyncContextManager["Applica
|
|||
self.create_task(
|
||||
coroutine,
|
||||
update=update,
|
||||
name=f"Application:{self.bot.id}:process_update_non_blocking"
|
||||
f":{handler}",
|
||||
name=(
|
||||
f"Application:{self.bot.id}:process_update_non_blocking"
|
||||
f":{handler}"
|
||||
),
|
||||
)
|
||||
else:
|
||||
any_blocking = True
|
||||
|
@ -1256,7 +1257,7 @@ class Application(Generic[BT, CCT, UD, CD, BD, JQ], AsyncContextManager["Applica
|
|||
if not self.persistence:
|
||||
raise ValueError(
|
||||
f"ConversationHandler {handler.name} "
|
||||
f"can not be persistent if application has no persistence"
|
||||
"can not be persistent if application has no persistence"
|
||||
)
|
||||
if self._initialized:
|
||||
self.create_task(
|
||||
|
|
|
@ -227,14 +227,16 @@ class CallbackDataCache:
|
|||
# Built a new nested list of buttons by replacing the callback data if needed
|
||||
buttons = [
|
||||
[
|
||||
# We create a new button instead of replacing callback_data in case the
|
||||
# same object is used elsewhere
|
||||
InlineKeyboardButton(
|
||||
btn.text,
|
||||
callback_data=self.__put_button(btn.callback_data, keyboard_data),
|
||||
(
|
||||
# We create a new button instead of replacing callback_data in case the
|
||||
# same object is used elsewhere
|
||||
InlineKeyboardButton(
|
||||
btn.text,
|
||||
callback_data=self.__put_button(btn.callback_data, keyboard_data),
|
||||
)
|
||||
if btn.callback_data
|
||||
else btn
|
||||
)
|
||||
if btn.callback_data
|
||||
else btn
|
||||
for btn in column
|
||||
]
|
||||
for column in reply_markup.inline_keyboard
|
||||
|
|
|
@ -414,7 +414,7 @@ class ConversationHandler(BaseHandler[Update, CCT]):
|
|||
):
|
||||
warn(
|
||||
f"Updates handled by {handler.__class__.__name__} only have information about "
|
||||
f"the user, so this handler won't ever be triggered if `per_chat=True`."
|
||||
"the user, so this handler won't ever be triggered if `per_chat=True`."
|
||||
f"{per_faq_link}",
|
||||
stacklevel=2,
|
||||
)
|
||||
|
|
|
@ -763,7 +763,7 @@ class _ChatUserBaseFilter(MessageFilter, ABC):
|
|||
def name(self) -> str:
|
||||
return (
|
||||
f"filters.{self.__class__.__name__}("
|
||||
f'{", ".join(str(s) for s in (self.usernames or self.chat_ids))})'
|
||||
f"{', '.join(str(s) for s in (self.usernames or self.chat_ids))})"
|
||||
)
|
||||
|
||||
@name.setter
|
||||
|
|
|
@ -468,7 +468,11 @@ class TestPassportWithoutRequest(TestPassportBase):
|
|||
assert passport_data.decrypted_data
|
||||
|
||||
async def test_wrong_key(self, bot):
|
||||
short_key = b"-----BEGIN RSA PRIVATE KEY-----\r\nMIIBOQIBAAJBAKU+OZ2jJm7sCA/ec4gngNZhXYPu+DZ/TAwSMl0W7vAPXAsLplBk\r\nO8l6IBHx8N0ZC4Bc65mO3b2G8YAzqndyqH8CAwEAAQJAWOx3jQFzeVXDsOaBPdAk\r\nYTncXVeIc6tlfUl9mOLyinSbRNCy1XicOiOZFgH1rRKOGIC1235QmqxFvdecySoY\r\nwQIhAOFeGgeX9CrEPuSsd9+kqUcA2avCwqdQgSdy2qggRFyJAiEAu7QHT8JQSkHU\r\nDELfzrzc24AhjyG0z1DpGZArM8COascCIDK42SboXj3Z2UXiQ0CEcMzYNiVgOisq\r\nBUd5pBi+2mPxAiAM5Z7G/Sv1HjbKrOGh29o0/sXPhtpckEuj5QMC6E0gywIgFY6S\r\nNjwrAA+cMmsgY0O2fAzEKkDc5YiFsiXaGaSS4eA=\r\n-----END RSA PRIVATE KEY-----"
|
||||
short_key = (
|
||||
b"-----BEGIN RSA PRIVATE"
|
||||
b" KEY-----\r\nMIIBOQIBAAJBAKU+OZ2jJm7sCA/ec4gngNZhXYPu+DZ/TAwSMl0W7vAPXAsLplBk\r\nO8l6IBHx8N0ZC4Bc65mO3b2G8YAzqndyqH8CAwEAAQJAWOx3jQFzeVXDsOaBPdAk\r\nYTncXVeIc6tlfUl9mOLyinSbRNCy1XicOiOZFgH1rRKOGIC1235QmqxFvdecySoY\r\nwQIhAOFeGgeX9CrEPuSsd9+kqUcA2avCwqdQgSdy2qggRFyJAiEAu7QHT8JQSkHU\r\nDELfzrzc24AhjyG0z1DpGZArM8COascCIDK42SboXj3Z2UXiQ0CEcMzYNiVgOisq\r\nBUd5pBi+2mPxAiAM5Z7G/Sv1HjbKrOGh29o0/sXPhtpckEuj5QMC6E0gywIgFY6S\r\nNjwrAA+cMmsgY0O2fAzEKkDc5YiFsiXaGaSS4eA=\r\n-----END"
|
||||
b" RSA PRIVATE KEY-----"
|
||||
)
|
||||
async with make_bot(token=bot.token, private_key=short_key) as b:
|
||||
passport_data = PassportData.de_json(RAW_PASSPORT_DATA, bot=b)
|
||||
with pytest.raises(PassportDecryptionError):
|
||||
|
|
|
@ -301,8 +301,10 @@ class TestInvoiceWithRequest(TestInvoiceBase):
|
|||
suggested_tip_amounts=self.suggested_tip_amounts,
|
||||
start_parameter=self.start_parameter,
|
||||
provider_data=self.provider_data,
|
||||
photo_url="https://raw.githubusercontent.com/"
|
||||
"python-telegram-bot/logos/master/logo/png/ptb-logo_240.png",
|
||||
photo_url=(
|
||||
"https://raw.githubusercontent.com/"
|
||||
"python-telegram-bot/logos/master/logo/png/ptb-logo_240.png"
|
||||
),
|
||||
photo_size=240,
|
||||
photo_width=240,
|
||||
photo_height=240,
|
||||
|
|
|
@ -382,9 +382,11 @@ class TestBasePersistence:
|
|||
methods.sort()
|
||||
with pytest.raises(
|
||||
TypeError,
|
||||
match=", ".join(methods)
|
||||
if sys.version_info < (3, 12)
|
||||
else ", ".join(f"'{i}'" for i in methods),
|
||||
match=(
|
||||
", ".join(methods)
|
||||
if sys.version_info < (3, 12)
|
||||
else ", ".join(f"'{i}'" for i in methods)
|
||||
),
|
||||
):
|
||||
BasePersistence()
|
||||
|
||||
|
@ -1256,7 +1258,7 @@ class TestBasePersistence:
|
|||
await papp.update_persistence()
|
||||
await asyncio.sleep(0.01)
|
||||
# Conversation should have been updated with the current state, i.e. None
|
||||
assert papp.persistence.updated_conversations == {"conv": ({(1, 1): 1})}
|
||||
assert papp.persistence.updated_conversations == {"conv": {(1, 1): 1}}
|
||||
assert papp.persistence.conversations == {"conv": {(1, 1): None}}
|
||||
|
||||
# Ensure that we warn the user about this!
|
||||
|
@ -1326,7 +1328,7 @@ class TestBasePersistence:
|
|||
|
||||
await papp.update_persistence()
|
||||
await asyncio.sleep(0.05)
|
||||
assert papp.persistence.updated_conversations == {"conv": ({(1, 1): 1})}
|
||||
assert papp.persistence.updated_conversations == {"conv": {(1, 1): 1}}
|
||||
# The result of the pending state wasn't retrieved by the CH yet, so we must be in
|
||||
# state `None`
|
||||
assert papp.persistence.conversations == {"conv": {(1, 1): None}}
|
||||
|
@ -1436,7 +1438,7 @@ class TestBasePersistence:
|
|||
assert papp.persistence.updated_conversations == {}
|
||||
|
||||
await papp.update_persistence()
|
||||
assert papp.persistence.updated_conversations == {"conv_1": ({(1, 1): 1})}
|
||||
assert papp.persistence.updated_conversations == {"conv_1": {(1, 1): 1}}
|
||||
# This is the important part: the persistence is updated with `None` when the conv ends
|
||||
assert papp.persistence.conversations == {"conv_1": {(1, 1): None}}
|
||||
|
||||
|
@ -1468,7 +1470,7 @@ class TestBasePersistence:
|
|||
)
|
||||
assert papp.persistence.updated_conversations == {}
|
||||
await papp.update_persistence()
|
||||
assert papp.persistence.updated_conversations == {"conv": ({(1, 1): 1})}
|
||||
assert papp.persistence.updated_conversations == {"conv": {(1, 1): 1}}
|
||||
assert papp.persistence.conversations == {"conv": {(1, 1): HandlerStates.STATE_1}}
|
||||
|
||||
papp.persistence.reset_tracking()
|
||||
|
|
|
@ -431,21 +431,25 @@ class TestConversationHandler:
|
|||
assert len(recwarn) == 13
|
||||
# now we test the messages, they are raised in the order they are inserted
|
||||
# into the conversation handler
|
||||
assert str(recwarn[0].message) == (
|
||||
"The `ConversationHandler` only handles updates of type `telegram.Update`. "
|
||||
assert (
|
||||
str(recwarn[0].message)
|
||||
== "The `ConversationHandler` only handles updates of type `telegram.Update`. "
|
||||
"StringCommandHandler handles updates of type `str`."
|
||||
)
|
||||
assert str(recwarn[1].message) == (
|
||||
"The `ConversationHandler` only handles updates of type `telegram.Update`. "
|
||||
assert (
|
||||
str(recwarn[1].message)
|
||||
== "The `ConversationHandler` only handles updates of type `telegram.Update`. "
|
||||
"StringRegexHandler handles updates of type `str`."
|
||||
)
|
||||
assert str(recwarn[2].message) == (
|
||||
"PollHandler will never trigger in a conversation since it has no information "
|
||||
assert (
|
||||
str(recwarn[2].message)
|
||||
== "PollHandler will never trigger in a conversation since it has no information "
|
||||
"about the chat or the user who voted in it. Do you mean the "
|
||||
"`PollAnswerHandler`?"
|
||||
)
|
||||
assert str(recwarn[3].message) == (
|
||||
"The `ConversationHandler` only handles updates of type `telegram.Update`. "
|
||||
assert (
|
||||
str(recwarn[3].message)
|
||||
== "The `ConversationHandler` only handles updates of type `telegram.Update`. "
|
||||
"The TypeHandler is set to handle NotUpdate."
|
||||
)
|
||||
|
||||
|
@ -481,17 +485,19 @@ class TestConversationHandler:
|
|||
+ per_faq_link
|
||||
)
|
||||
assert str(recwarn[10].message) == (
|
||||
"If 'per_message=False', 'CallbackQueryHandler' will not be tracked for "
|
||||
"every message." + per_faq_link
|
||||
"If 'per_message=False', 'CallbackQueryHandler' will not be tracked for every message."
|
||||
+ per_faq_link
|
||||
)
|
||||
assert str(recwarn[11].message) == (
|
||||
"Using `conversation_timeout` with nested conversations is currently not "
|
||||
assert (
|
||||
str(recwarn[11].message)
|
||||
== "Using `conversation_timeout` with nested conversations is currently not "
|
||||
"supported. You can still try to use it, but it will likely behave differently"
|
||||
" from what you expect."
|
||||
)
|
||||
|
||||
assert str(recwarn[12].message) == (
|
||||
"If 'per_message=True' is used, 'per_chat=True' should also be used, "
|
||||
assert (
|
||||
str(recwarn[12].message)
|
||||
== "If 'per_message=True' is used, 'per_chat=True' should also be used, "
|
||||
"since message IDs are not globally unique."
|
||||
)
|
||||
|
||||
|
@ -721,8 +727,9 @@ class TestConversationHandler:
|
|||
Path(recwarn[0].filename)
|
||||
== PROJECT_ROOT_PATH / "telegram" / "ext" / "_conversationhandler.py"
|
||||
), "wrong stacklevel!"
|
||||
assert str(recwarn[0].message) == (
|
||||
"'callback' returned state 69 which is unknown to the ConversationHandler xyz."
|
||||
assert (
|
||||
str(recwarn[0].message)
|
||||
== "'callback' returned state 69 which is unknown to the ConversationHandler xyz."
|
||||
)
|
||||
|
||||
async def test_conversation_handler_per_chat(self, app, bot, user1, user2):
|
||||
|
|
|
@ -829,20 +829,22 @@ class TestFilters:
|
|||
)
|
||||
|
||||
def test_filters_file_extension_name(self):
|
||||
assert filters.Document.FileExtension("jpg").name == (
|
||||
"filters.Document.FileExtension('jpg')"
|
||||
assert (
|
||||
filters.Document.FileExtension("jpg").name == "filters.Document.FileExtension('jpg')"
|
||||
)
|
||||
assert filters.Document.FileExtension("JPG").name == (
|
||||
"filters.Document.FileExtension('jpg')"
|
||||
assert (
|
||||
filters.Document.FileExtension("JPG").name == "filters.Document.FileExtension('jpg')"
|
||||
)
|
||||
assert filters.Document.FileExtension("jpg", case_sensitive=True).name == (
|
||||
"filters.Document.FileExtension('jpg', case_sensitive=True)"
|
||||
assert (
|
||||
filters.Document.FileExtension("jpg", case_sensitive=True).name
|
||||
== "filters.Document.FileExtension('jpg', case_sensitive=True)"
|
||||
)
|
||||
assert filters.Document.FileExtension("JPG", case_sensitive=True).name == (
|
||||
"filters.Document.FileExtension('JPG', case_sensitive=True)"
|
||||
assert (
|
||||
filters.Document.FileExtension("JPG", case_sensitive=True).name
|
||||
== "filters.Document.FileExtension('JPG', case_sensitive=True)"
|
||||
)
|
||||
assert filters.Document.FileExtension(".jpg").name == (
|
||||
"filters.Document.FileExtension('.jpg')"
|
||||
assert (
|
||||
filters.Document.FileExtension(".jpg").name == "filters.Document.FileExtension('.jpg')"
|
||||
)
|
||||
assert filters.Document.FileExtension("").name == "filters.Document.FileExtension('')"
|
||||
assert filters.Document.FileExtension(None).name == "filters.Document.FileExtension(None)"
|
||||
|
@ -2015,8 +2017,7 @@ class TestFilters:
|
|||
|
||||
assert (
|
||||
str(filters.TEXT & (filters.FORWARDED | filters.Entity(MessageEntity.MENTION)))
|
||||
== "<filters.TEXT and <filters.FORWARDED or "
|
||||
"filters.Entity(mention)>>"
|
||||
== "<filters.TEXT and <filters.FORWARDED or filters.Entity(mention)>>"
|
||||
)
|
||||
|
||||
def test_xor_filters(self, update):
|
||||
|
@ -2056,8 +2057,7 @@ class TestFilters:
|
|||
|
||||
assert (
|
||||
str(filters.FORWARDED & (filters.TEXT ^ filters.User(123)))
|
||||
== "<filters.FORWARDED and <filters.TEXT xor "
|
||||
"filters.User(123)>>"
|
||||
== "<filters.FORWARDED and <filters.TEXT xor filters.User(123)>>"
|
||||
)
|
||||
|
||||
def test_xor_regex_filters(self, update):
|
||||
|
|
|
@ -136,8 +136,10 @@ BASE_GAME_SCORE = 60 # Base game score for game tests
|
|||
|
||||
xfail = pytest.mark.xfail(
|
||||
bool(GITHUB_ACTION), # This condition is only relevant for github actions game tests.
|
||||
reason="Can fail due to race conditions when multiple test suites "
|
||||
"with the same bot token are run at the same time",
|
||||
reason=(
|
||||
"Can fail due to race conditions when multiple test suites "
|
||||
"with the same bot token are run at the same time"
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
|
@ -684,8 +686,10 @@ class TestBotWithoutRequest:
|
|||
"title": "test_result",
|
||||
"id": "123",
|
||||
"type": "document",
|
||||
"document_url": "https://raw.githubusercontent.com/python-telegram-bot"
|
||||
"/logos/master/logo/png/ptb-logo_240.png",
|
||||
"document_url": (
|
||||
"https://raw.githubusercontent.com/python-telegram-bot"
|
||||
"/logos/master/logo/png/ptb-logo_240.png"
|
||||
),
|
||||
"mime_type": "image/png",
|
||||
"caption": "ptb_logo",
|
||||
"input_message_content": {"message_text": "imc"},
|
||||
|
@ -713,8 +717,10 @@ class TestBotWithoutRequest:
|
|||
InlineQueryResultArticle("12", "second", InputMessageContentDWPP("second")),
|
||||
InlineQueryResultDocument(
|
||||
id="123",
|
||||
document_url="https://raw.githubusercontent.com/python-telegram-bot/logos/master/"
|
||||
"logo/png/ptb-logo_240.png",
|
||||
document_url=(
|
||||
"https://raw.githubusercontent.com/python-telegram-bot/logos/master/"
|
||||
"logo/png/ptb-logo_240.png"
|
||||
),
|
||||
title="test_result",
|
||||
mime_type="image/png",
|
||||
caption="ptb_logo",
|
||||
|
@ -787,9 +793,11 @@ class TestBotWithoutRequest:
|
|||
"title": "test_result",
|
||||
"id": "123",
|
||||
"type": "document",
|
||||
"document_url": "https://raw.githubusercontent.com/"
|
||||
"python-telegram-bot/logos/master/logo/png/"
|
||||
"ptb-logo_240.png",
|
||||
"document_url": (
|
||||
"https://raw.githubusercontent.com/"
|
||||
"python-telegram-bot/logos/master/logo/png/"
|
||||
"ptb-logo_240.png"
|
||||
),
|
||||
"mime_type": "image/png",
|
||||
"caption": "ptb_logo",
|
||||
"input_message_content": {"message_text": "imc"},
|
||||
|
@ -806,8 +814,10 @@ class TestBotWithoutRequest:
|
|||
InlineQueryResultArticle("12", "second", InputMessageContentDWPP("second")),
|
||||
InlineQueryResultDocument(
|
||||
id="123",
|
||||
document_url="https://raw.githubusercontent.com/python-telegram-bot/logos/master/"
|
||||
"logo/png/ptb-logo_240.png",
|
||||
document_url=(
|
||||
"https://raw.githubusercontent.com/python-telegram-bot/logos/master/"
|
||||
"logo/png/ptb-logo_240.png"
|
||||
),
|
||||
title="test_result",
|
||||
mime_type="image/png",
|
||||
caption="ptb_logo",
|
||||
|
@ -871,9 +881,11 @@ class TestBotWithoutRequest:
|
|||
"title": "test_result",
|
||||
"id": "123",
|
||||
"type": "document",
|
||||
"document_url": "https://raw.githubusercontent.com/"
|
||||
"python-telegram-bot/logos/master/logo/png/"
|
||||
"ptb-logo_240.png",
|
||||
"document_url": (
|
||||
"https://raw.githubusercontent.com/"
|
||||
"python-telegram-bot/logos/master/logo/png/"
|
||||
"ptb-logo_240.png"
|
||||
),
|
||||
"mime_type": "image/png",
|
||||
"caption": "ptb_logo",
|
||||
"parse_mode": "Markdown",
|
||||
|
@ -895,8 +907,10 @@ class TestBotWithoutRequest:
|
|||
InlineQueryResultArticle("12", "second", InputMessageContentDWPP("second")),
|
||||
InlineQueryResultDocument(
|
||||
id="123",
|
||||
document_url="https://raw.githubusercontent.com/python-telegram-bot/logos/master/"
|
||||
"logo/png/ptb-logo_240.png",
|
||||
document_url=(
|
||||
"https://raw.githubusercontent.com/python-telegram-bot/logos/master/"
|
||||
"logo/png/ptb-logo_240.png"
|
||||
),
|
||||
title="test_result",
|
||||
mime_type="image/png",
|
||||
caption="ptb_logo",
|
||||
|
@ -1398,9 +1412,11 @@ class TestBotWithoutRequest:
|
|||
data.get("caption") == caption,
|
||||
data["parse_mode"] == ParseMode.HTML,
|
||||
data["reply_to_message_id"] == media_message.message_id,
|
||||
data["reply_markup"] == keyboard.to_json()
|
||||
if json_keyboard
|
||||
else keyboard.to_dict(),
|
||||
(
|
||||
data["reply_markup"] == keyboard.to_json()
|
||||
if json_keyboard
|
||||
else keyboard.to_dict()
|
||||
),
|
||||
data["disable_notification"] is True,
|
||||
data["caption_entities"]
|
||||
== [MessageEntity(MessageEntity.BOLD, 0, 4).to_dict()],
|
||||
|
@ -2244,7 +2260,7 @@ class TestBotWithRequest:
|
|||
await bot.send_chat_action(chat_id, "unknown action")
|
||||
|
||||
async def test_answer_inline_query_current_offset_error(self, bot, inline_results):
|
||||
with pytest.raises(ValueError, match=("`current_offset` and `next_offset`")):
|
||||
with pytest.raises(ValueError, match="`current_offset` and `next_offset`"):
|
||||
await bot.answer_inline_query(
|
||||
1234, results=inline_results, next_offset=42, current_offset=51
|
||||
)
|
||||
|
@ -2513,8 +2529,9 @@ class TestBotWithRequest:
|
|||
message = await bot.send_game(chat_id, game_short_name, protect_content=True)
|
||||
|
||||
assert message.game
|
||||
assert message.game.description == (
|
||||
"A no-op test game, for python-telegram-bot bot framework testing."
|
||||
assert (
|
||||
message.game.description
|
||||
== "A no-op test game, for python-telegram-bot bot framework testing."
|
||||
)
|
||||
assert message.game.animation.file_id
|
||||
# We added some test bots later and for some reason the file size is not the same for them
|
||||
|
|
Loading…
Reference in a new issue