Skip to content
This repository was archived by the owner on Feb 23, 2026. It is now read-only.

chore: avoid checking instance on each stream call#529

Merged
daniel-sanche merged 13 commits into
mainfrom
improve_streams
May 3, 2024
Merged

chore: avoid checking instance on each stream call#529
daniel-sanche merged 13 commits into
mainfrom
improve_streams

Conversation

@daniel-sanche
Copy link
Copy Markdown
Contributor

@daniel-sanche daniel-sanche commented Sep 8, 2023

_wrap_stream_errors currently tests the type of the call on each call. This PR moves the logic to happen once, at method wrap time.

@daniel-sanche daniel-sanche requested review from a team September 8, 2023 00:01
@product-auto-label product-auto-label Bot added the size: s Pull request size is small. label Sep 8, 2023
@parthea parthea marked this pull request as draft September 19, 2023 16:54
@parthea
Copy link
Copy Markdown
Contributor

parthea commented Sep 19, 2023

Converting to draft as presubmits are failing

@product-auto-label product-auto-label Bot added size: m Pull request size is medium. and removed size: s Pull request size is small. labels Feb 10, 2024
@daniel-sanche daniel-sanche marked this pull request as ready for review February 10, 2024 00:29
@daniel-sanche
Copy link
Copy Markdown
Contributor Author

@parthea I fixed the tests.

I'm prioritizing some of these gapic performance improvements, so I'm fine if you'd rather close this for now and revisit it later. But this one should be fairly straight-forward

@vchudnov-g vchudnov-g self-assigned this Feb 12, 2024
Copy link
Copy Markdown
Contributor

@parthea parthea left a comment

Choose a reason for hiding this comment

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

LGTM, but please wait for @vchudnov-g to review

@parthea
Copy link
Copy Markdown
Contributor

parthea commented Feb 27, 2024

@vchudnov-g Please could you review?

Copy link
Copy Markdown
Contributor

@vchudnov-g vchudnov-g left a comment

Choose a reason for hiding this comment

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

Thanks for doing this!


@pytest.mark.asyncio
async def test_wrap_stream_errors_type_error():
async def test_wrap_errors_type_error():
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It would be helpful to comment that the explicit type of error you're checking for is the "Unexpected type of callable" (which now happens at wrapping time). As per my other comment, if that were a specialized subclass of TypeError, we could check for that and the code would be self-documenting, so we wouldn't need an extra comment.

return _wrap_stream_errors(callable_, _WrappedStreamStreamCall)
else:
return _wrap_stream_errors(callable_)
raise TypeError("Unexpected type of callable: {}".format(type(callable_)))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit (not a blocker, consider for the future): consider in cases like this raising a custom subclass of TypeError, so that we can check the exception type in tests

@daniel-sanche daniel-sanche merged commit ab22afd into main May 3, 2024
@daniel-sanche daniel-sanche deleted the improve_streams branch May 3, 2024 19:23
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

size: m Pull request size is medium.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants