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

feat: add get_task_result_stream to new client #351

Merged
merged 3 commits into from
Nov 8, 2024
Merged

Conversation

masci
Copy link
Member

@masci masci commented Nov 6, 2024

This PR ports the last method missing from AsyncSessionClient, get_task_result_stream.

Fixes #335

Notes for the reviewer:

  • async methods returning Coroutine[AsyncGenerator] when converted with async_to_sync return AsyncGenerator, that we can't use in sync calls. To overcome this limitation, generator_wrapper was added that consumes the async generator under the hood and returns a list
  • end-to-end tests were update to use Client
  • unit tests were added to cover the new wrapper

@coveralls
Copy link

coveralls commented Nov 6, 2024

Coverage Status

coverage: 71.351% (+3.2%) from 68.189%
when pulling 9ac6ea6 on massi/client-streaming
into b96db7a on main.

Copy link
Collaborator

@logan-markewich logan-markewich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm honestly, nice

Copy link
Contributor

@nerdai nerdai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Just had one question on _R generic param that was introduced and I couldn't see where it was being used?

except RuntimeError:
return _SyncClient(**self.model_dump())

msg = "You cannot use the sync client within an async event loop - just await the async methods directly."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, was this something we were running into before. Anyways, nice catch!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This problem always existed but didn't run into it until @logan-markewich made me notice!

# Generic parameter for the wrapped generator method
_P = ParamSpec("_P")
# Generic parameter for the wrapped generator method return value
_R = TypeVar("_R")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly dumb question as perhaps I just missed this, but where are we using this generic param?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not dumb, leftover! I'll remove it, good catch!

@masci masci merged commit 955ef73 into main Nov 8, 2024
10 checks passed
@masci masci deleted the massi/client-streaming branch November 8, 2024 11:50
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.

Port existing clients to the new Client class
4 participants