Skip to content

Introduce keyword-only arguments for auxiliary arguments of Bot methods #3016

@Bibo-Joshi

Description

@Bibo-Joshi

Current situation

All bot methods have arguments {read, write, connect, pool}_timeout and api_kwargs, which are added by PTB and do not correspond to arguments defined by the Bot API.
When a bot API update introduces new arguments to a method, we currently have to add them after the arguments mentioned above to ensure backwards compatibility for people that pass the arguments as positional arguments. This leads to constructs like

async def send_message(
self,
chat_id: Union[int, str],
text: str,
parse_mode: ODVInput[str] = DEFAULT_NONE,
disable_web_page_preview: ODVInput[bool] = DEFAULT_NONE,
disable_notification: DVInput[bool] = DEFAULT_NONE,
reply_to_message_id: int = None,
reply_markup: ReplyMarkup = None,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
connect_timeout: ODVInput[float] = DEFAULT_NONE,
pool_timeout: ODVInput[float] = DEFAULT_NONE,
api_kwargs: JSONDict = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
entities: Union[List["MessageEntity"], Tuple["MessageEntity", ...]] = None,
protect_content: ODVInput[bool] = DEFAULT_NONE,
) -> Message:

which is not very nice and may lead to people passing values to the wrong parameters if they rely on the order defined by the bot API.

Proposed solution

Make the arguments {read, write, connect, pool}_timeout and api_kwargs keyword-only arguments.

ToDo

A PR for this issue should include:

  • Update the definitions of all methods of the Bot class that have these argumemts
  • The docstrings should be updated to reflect the order of the signature
  • all corresponding methods of the ExtBot class should be updated as well
  • as should all shortcut methods like Message.reply_text, Chat.send_message etc
  • It should be checked if the rendered HTML documentation includes the * in the displayed signature. If it does not, the docstrings should include some other indicator that these arguments are keyward-only arguments. How this should look may be discussed at a later stage
  • The unit tests must be updated accordingly. Running the test suit to see which tests fail after the changes should be a good start. Additionally, we should make sure that the auxiliary functions that currently test the signature definition of shortcut methods are still working as expected. This is a bit more intricate, so the development team can help with that.

Additional Info

We have a contribution guide

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions