-
Notifications
You must be signed in to change notification settings - Fork 88
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
Conversation
Converting to draft as presubmits are failing |
@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 |
There was a problem hiding this 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
@vchudnov-g Please could you review? |
There was a problem hiding this 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(): |
There was a problem hiding this comment.
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_))) |
There was a problem hiding this comment.
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
_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.