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

Raise a neater RuntimeError when the correct async deps are not installed. #826

Merged
merged 5 commits into from
Nov 2, 2023

Conversation

tomchristie
Copy link
Member

@tomchristie tomchristie commented Oct 13, 2023

Closes #825.

example.py

import httpcore
import asyncio


async def main():
    async with httpcore.AsyncConnectionPool() as pool:
        response = await pool.request("GET", "https://www.example.com")
    print(response)


asyncio.run(main())

output:

$ venv/bin/python ./example.py 
Traceback (most recent call last):
  File "/Users/tomchristie/Temp/./example.py", line 11, in <module>
    asyncio.run(main())
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
    return future.result()
  File "/Users/tomchristie/Temp/./example.py", line 6, in main
    async with httpcore.AsyncConnectionPool() as pool:
  File "/Users/tomchristie/GitHub/encode/httpcore/httpcore/_async/connection_pool.py", line 331, in __aenter__
    async with self._pool_lock:
  File "/Users/tomchristie/GitHub/encode/httpcore/httpcore/_synchronization.py", line 64, in __aenter__
    self.setup()
  File "/Users/tomchristie/GitHub/encode/httpcore/httpcore/_synchronization.py", line 56, in setup
    self._backend = current_async_library()
  File "/Users/tomchristie/GitHub/encode/httpcore/httpcore/_synchronization.py", line 35, in current_async_library
    raise RuntimeError(
RuntimeError: Running with asyncio requires installation of 'httpcore[asyncio]'.

Compare this against... #825 (comment)

@chamikabm
Copy link

Any plan on releasing this fix ?

@tomchristie
Copy link
Member Author

Any plan on releasing this fix ?

Yes. This PR is currently blocked on an approving review from an @encode/maintainers member.

Either:

  • If any of the existing reviewers/commenters on this issue would like I can send an invitation.
  • We get a review from an existing member.

@Kludex Kludex requested review from zanieb and a team October 30, 2023 12:11
@tomchristie tomchristie merged commit 08b3eee into master Nov 2, 2023
5 checks passed
@tomchristie tomchristie deleted the neater-exception-when-async-deps-not-installed branch November 2, 2023 14:24
@tomchristie tomchristie mentioned this pull request Nov 2, 2023
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.

AttributeError: 'AsyncLock' object has no attribute '_anyio_lock'
4 participants