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

Add types and code generation for event stream operation signatures #318

Merged
merged 6 commits into from
Oct 18, 2024

Conversation

JordonPhillips
Copy link
Contributor

This adds in the interfaces for event streams and updates code generation to use them.

Example generated operation:

async def stream_messages(
    self,
    input: StreamMessagesInput,
    plugins: list[Plugin] | None = None,
) -> EventStream[
    InputEventStream[MessageStream],
    OutputEventStream[MessageStream],
    StreamMessagesOutput,
]:
    raise NotImplementedError()

These were part of separate prs that included http context, which has been removed. Doc strings have also been majorly beefed up. Example useage from the beefed up docs:

async def main():
    client = ChatClient()
    input = StreamMessagesInput(chat_room="aws-python-sdk", username="hunter7")

    async with client.stream_messages(input=input) as stream:
        stream.input_stream.send(MessageStreamMessage("Chat logger starting up."))
        response_handler = handle_output(stream)
        stream.input_stream.send(MessageStreamMessage("Chat logger active."))
        await response_handler

    async def handle_output(stream: EventStream) -> None:
        _, output_stream = await stream.await_output()
        async for event in output_stream:
            match event:
                case MessageStreamMessage():
                    print(event.value)
                case MessageStreamShutdown():
                    return
                case _:
                    stream.input_stream.send(
                        MessageStreamMessage("Unknown message type received. Shutting down.")
                    )
                    return

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@JordonPhillips JordonPhillips requested a review from a team as a code owner October 17, 2024 13:06
@JordonPhillips JordonPhillips force-pushed the event-stream-signature branch 2 times, most recently from 66caf5d to ff1df13 Compare October 17, 2024 13:24
@JordonPhillips
Copy link
Contributor Author

I also had to add suppressions for new protocol tests that assert http-binding behaviors. We'll be re-writing all that binding code soon, so there's little value in fixing it now.

@JordonPhillips JordonPhillips changed the title Event stream signature Add types and code generation for event stream operation signatures Oct 17, 2024
@JordonPhillips
Copy link
Contributor Author

I split the suppressions out into another pr since it was blocking everything

This adds in the EventStream interfaces that operations will use as
their return types.
This adds a bidirectional event stream to the test package so that
new code generation for event streams can be examined.
This updates operation generation to generate event stream operations
with the EventStream type as its return value.

It also updates union generation so that unions contain their own
deserialize functions. This is needed to make the them pass the type
check, but also it is best to have them own as much of that as
possible so that the deserializer function can be left to only
dispatch duty.
Copy link
Contributor

@nateprewitt nateprewitt left a comment

Choose a reason for hiding this comment

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

Couple typos, otherwise looks good.

Fix comment typos

Co-authored-by: Nate Prewitt <[email protected]>
@JordonPhillips
Copy link
Contributor Author

No idea why codecov ate it

Copy link
Contributor

@nateprewitt nateprewitt left a comment

Choose a reason for hiding this comment

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

Looks like a transient 503 for CodeCov, succeeded on retry.

@JordonPhillips JordonPhillips merged commit 0fc3746 into develop Oct 18, 2024
5 checks passed
@JordonPhillips JordonPhillips deleted the event-stream-signature branch October 18, 2024 20:42
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.

2 participants