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

Adding __aenter__ and __aexit__ Methods to AsyncHTMLSession #556

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Curtidor
Copy link

Changes Overview

  • Added __aenter__ method, returning the instance of AsyncHTMLSession within an asynchronous context.
  • Added __aexit__ method, ensuring proper closing of the session upon context exit.
  • Created a new test suite (test_async_context_manager) to validate the functionality of the async context manager.
  • Added test case to the test suite to ensure that the session can successfully make an HTTP GET request within the async context.

Description

This merge request introduces the addition of __aenter__ and __aexit__ methods to the AsyncHTMLSession class, providing support for using the class as an asynchronous context manager. Additionally, a test suite has been created to verify the functionality of the async context manager. Also, some imports have been moved to better align with PEP 8 – style guide.

Motivation

The introduction of the __aenter__ and __aexit__ methods allows users of the AsyncHTMLSession class to easily manage the lifecycle of the session within an asynchronous context. The __aenter__ method returns the instance itself, enabling seamless integration with asynchronous context management. On the other hand, the __aexit__ method ensures that the session is properly closed when exiting the context.

Test Results

The new test suite (test_async_context_manager) has been executed successfully, validating the behavior of the async context manager. The test case confirms that the AsyncHTMLSession instance can be used within an asynchronous context to make an HTTP GET request, and the session is properly closed upon exiting the context.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant