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

Support AIOHTTPClient init without running event loop #1271

Merged
merged 5 commits into from
Mar 20, 2024
Merged

Support AIOHTTPClient init without running event loop #1271

merged 5 commits into from
Mar 20, 2024

Conversation

OldSneerJaw
Copy link
Contributor

@OldSneerJaw OldSneerJaw commented Mar 14, 2024

Lazily instantiates and caches an aiohttp ClientSession at the points in time that it is actually used so that AIOHTTPClient can be initialized without a running event loop (e.g. when setting stripe.default_http_client = stripe.AIOHTTPClient() at the top level of a module).

Related to issue #327.

@CLAassistant
Copy link

CLAassistant commented Mar 14, 2024

CLA assistant check
All committers have signed the CLA.

OldSneerJaw and others added 4 commits March 14, 2024 17:11
Lazily instantiates and caches an aiohttp `ClientSession` at the points that it is actually used so that `AIOHTTPClient` can be initialized without a running event loop (e.g. when setting `stripe.default_http_client = stripe.AIOHTTPClient()` at the top level of a module).
Fixes a type checking error by having `AIOHTTPClient`'s `_session` property assert that the `aiohttp` module exists
The `functools.cached_property` decorator did not exist in Python 3.7, so `AIOHTTPClient`'s `_session` has been changed into a regular property that performs caching manually by storing the `ClientSession` object as a member of the instance.
@OldSneerJaw
Copy link
Contributor Author

I fixed the typing errors and removed the usage of the cached_property decorator since it's not available in Python 3.7.

Ensures `AIOHTTPClient`'s `_cached_session` attribute is defined in the initializer.
@OldSneerJaw
Copy link
Contributor Author

@richardm-stripe: Bump.

@richardm-stripe
Copy link
Contributor

richardm-stripe commented Mar 20, 2024

This looks good to me! It will be in Thursday's beta release.

Sorry for the silence on this, I appreciate the bump. Thank you for teaching me about about @cached_property (too bad we can't use it yet 😞 ) and handling the backwards compatibility/typing errors.

@richardm-stripe richardm-stripe merged commit c71b88d into stripe:beta Mar 20, 2024
15 checks passed
@OldSneerJaw OldSneerJaw deleted the aiohttp-init-sync branch March 20, 2024 21:26
richardm-stripe pushed a commit that referenced this pull request Apr 3, 2024
* Support AIOHTTPClient init without running event loop

Lazily instantiates and caches an aiohttp `ClientSession` at the points that it is actually used so that `AIOHTTPClient` can be initialized without a running event loop (e.g. when setting `stripe.default_http_client = stripe.AIOHTTPClient()` at the top level of a module).

* Format

* Assert aiohttp module is present in AIOHTTPClient

Fixes a type checking error by having `AIOHTTPClient`'s `_session` property assert that the `aiohttp` module exists

* Remove dependence on cached_property

The `functools.cached_property` decorator did not exist in Python 3.7, so `AIOHTTPClient`'s `_session` has been changed into a regular property that performs caching manually by storing the `ClientSession` object as a member of the instance.

* Define aiohttp cached session attribute in init

Ensures `AIOHTTPClient`'s `_cached_session` attribute is defined in the initializer.
richardm-stripe pushed a commit that referenced this pull request Apr 3, 2024
* Support AIOHTTPClient init without running event loop

Lazily instantiates and caches an aiohttp `ClientSession` at the points that it is actually used so that `AIOHTTPClient` can be initialized without a running event loop (e.g. when setting `stripe.default_http_client = stripe.AIOHTTPClient()` at the top level of a module).

* Format

* Assert aiohttp module is present in AIOHTTPClient

Fixes a type checking error by having `AIOHTTPClient`'s `_session` property assert that the `aiohttp` module exists

* Remove dependence on cached_property

The `functools.cached_property` decorator did not exist in Python 3.7, so `AIOHTTPClient`'s `_session` has been changed into a regular property that performs caching manually by storing the `ClientSession` object as a member of the instance.

* Define aiohttp cached session attribute in init

Ensures `AIOHTTPClient`'s `_cached_session` attribute is defined in the initializer.
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.

None yet

3 participants