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

chore: avoid checking instance on each stream call #529

Merged
merged 13 commits into from
May 3, 2024

Conversation

daniel-sanche
Copy link
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 as code owners 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
Collaborator

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
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
Collaborator

@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
Collaborator

parthea commented Feb 27, 2024

@vchudnov-g Please could you review?

Copy link
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!


await wrapped_callable(1, 2, three="four")
multicallable.assert_called_once_with(1, 2, three="four")
assert mock_call.wait_for_connection.call_count == 1


@pytest.mark.asyncio
async def test_wrap_stream_errors_type_error():
async def test_wrap_errors_type_error():
Copy link
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.

else:
return _wrap_stream_errors(callable_)
raise TypeError("Unexpected type of callable: {}".format(type(callable_)))
Copy link
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
27 checks passed
@daniel-sanche daniel-sanche deleted the improve_streams branch May 3, 2024 19:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size: m Pull request size is medium.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants