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

Async generators are implemented incorrectly #704

Closed
Andrew-Chen-Wang opened this issue Mar 31, 2023 · 2 comments
Closed

Async generators are implemented incorrectly #704

Andrew-Chen-Wang opened this issue Mar 31, 2023 · 2 comments
Labels
status: waiting for feedback waiting for feedback from the submitter type: question question directed at the library

Comments

@Andrew-Chen-Wang
Copy link

Andrew-Chen-Wang commented Mar 31, 2023

Issue Summary

Testing the new async client, but async generators don't seem to be working correctly.

There are a bunch of areas in the code base that await stream_async and some don't await the stream_async.

Steps to Reproduce

Just run the below code; it's a simple API call

Code Snippet

twilio_http_client = AsyncTwilioHttpClient()
twilio_client = Client(
    env.get('TWILIO_ACCOUNT_SID'),
    env.get('TWILIO_AUTH_TOKEN'),
    http_client=twilio_http_client
)

# Test 1
await twilio_client.incoming_phone_numbers.list_async()
# Test 2
[x async for x in twilio_client.incoming_phone_numbers.list_async()]
[x async for x in await twilio_client.incoming_phone_numbers.list_async()]
# Test 3
[x for x in await twilio_client.incoming_phone_numbers.list_async()]

The problem is:

TypeError: object async_generator can't be used in 'await' expression

Exception/Log

Traceback (most recent call last):
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/pydevconsole.py", line 367, in runcode
    loop.run_until_complete(coro)
  File "/usr/local/Cellar/python@3.10/3.10.4/Frameworks/Python.framework/Versions/3.10/lib/python3.10/asyncio/base_events.py", line 646, in run_until_complete
    return future.result()
  File "<input>", line 1, in <module>
  File "/Users/andrewcwang/Work/Code/test/python/twilio-transcription/venv/lib/python3.10/site-packages/twilio/rest/api/v2010/account/incoming_phone_number/__init__.py", line 1324, in list_async
    await self.stream_async(
  File "/Users/andrewcwang/Work/Code/test/python/twilio-transcription/venv/lib/python3.10/site-packages/twilio/rest/api/v2010/account/incoming_phone_number/__init__.py", line 1254, in stream_async
    return await self._version.stream_async(page, limits["limit"])
TypeError: object async_generator can't be used in 'await' expression

Or if you use async for without await

Traceback (most recent call last):
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/pydevconsole.py", line 367, in runcode
    loop.run_until_complete(coro)
  File "/usr/local/Cellar/python@3.10/3.10.4/Frameworks/Python.framework/Versions/3.10/lib/python3.10/asyncio/base_events.py", line 646, in run_until_complete
    return future.result()
  File "<input>", line 1, in <module>
TypeError: 'async for' requires an object with __aiter__ method, got coroutine

Technical details:

  • twilio-python version: 8.0.0-rc.1
  • python version: 3.10
@childish-sambino
Copy link
Contributor

Should be fixed by #701

@childish-sambino childish-sambino added type: question question directed at the library status: waiting for feedback waiting for feedback from the submitter labels Mar 31, 2023
@Andrew-Chen-Wang
Copy link
Author

missed this thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting for feedback waiting for feedback from the submitter type: question question directed at the library
Projects
None yet
Development

No branches or pull requests

2 participants