Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add context manager support for bot client #1468

Merged
merged 2 commits into from Apr 22, 2024
Merged

Conversation

JrooTJunior
Copy link
Member

@JrooTJunior JrooTJunior commented Apr 22, 2024

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.

From now you can use:

async with Bot(...) as bot:
    ...

instead of

async with Bot(...).context():
    ...

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.
@JrooTJunior JrooTJunior added the enhancement Make it better! label Apr 22, 2024
@github-actions github-actions bot added the 3.x Issue or PR for stable 3.x version label Apr 22, 2024
Copy link

github-actions bot commented Apr 22, 2024

✔️ Changelog found.

Thank you for adding a description of the changes

Copy link

codecov bot commented Apr 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (9756dac) to head (b2b2fcf).

❗ Current head b2b2fcf differs from pull request most recent head 5684bc3. Consider uploading reports for the commit 5684bc3 to get more accurate results

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##           dev-3.x     #1468   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          422       422           
  Lines        10932     10937    +5     
=========================================
+ Hits         10932     10937    +5     
Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
aiogram/client/bot.py 100.00% <100.00%> (ø)

@JrooTJunior JrooTJunior marked this pull request as ready for review April 22, 2024 20:42
@JrooTJunior JrooTJunior merged commit 4729978 into dev-3.x Apr 22, 2024
25 checks passed
@JrooTJunior JrooTJunior deleted the feature/bot-context branch April 22, 2024 20:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.x Issue or PR for stable 3.x version enhancement Make it better!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant