Add context manager support for bot client (#1468)

* Add context manager support for bot client

The bot client now supports the context manager protocol, providing automatic resource management. This enhancement helps to automatically close the session when leaving the context, which cleans up resources better. The documentation and tests have been updated accordingly to illustrate this new feature. Moreover, an example of usage without a dispatcher has been provided to clarify its use in simple cases.

* Added changelog
This commit is contained in:
Alex Root Junior 2024-04-22 23:42:47 +03:00 committed by GitHub
parent 9756dac877
commit 4729978c60
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 84 additions and 0 deletions

13
CHANGES/1468.feature.rst Normal file
View file

@ -0,0 +1,13 @@
Added context manager interface to Bot instance, from now you can use:
.. code-block:: python
async with Bot(...) as bot:
...
instead of
.. code-block:: python
async with Bot(...).context():
...