[grpcio] Fix AioRpcError.trailing_metadata and Metadata iteration#15899
Open
pboulos wants to merge 1 commit into
Open
[grpcio] Fix AioRpcError.trailing_metadata and Metadata iteration#15899pboulos wants to merge 1 commit into
pboulos wants to merge 1 commit into
Conversation
2ce78ec to
576278d
Compare
Author
|
I originally included a regression test, but I saw the comments made on other PRs around performance considerations of adding tests so I opted to remove it. See it below for reference: # Regression test for the AioRpcError.trailing_metadata() override: it must
# return the async grpc.aio.Metadata (iterating as (key, value) tuples), not the
# synchronous tuple[_Metadatum, ...] inherited from grpc.RpcError.
def check_aio_rpc_error_trailing_metadata(error: grpc.aio.AioRpcError) -> None:
assert_type(error.trailing_metadata(), grpc.aio.Metadata)
for key, value in error.trailing_metadata():
assert_type(key, str)
assert_type(value, grpc.aio._MetadataValue) |
[pre-commit.ci] auto fixes from pre-commit.com hooks
5b06964 to
af81a5e
Compare
Contributor
|
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I encountered a typing issue when using
grpc.aioand figured I would write a PR to solve it at source.Two related fixes to the async (
grpc.aio) metadata types:AioRpcError.trailing_metadata()inherited the synchronousRpcError.trailing_metadata() -> tuple[_Metadatum, ...], but at runtime returns agrpc.aio.Metadata(
_call.py).Added the override.
grpc.aio.Metadatawas modelled as aMapping, but the runtime class is aCollectionthat iterates(key, value)tuples(
_metadata.py).Re-based on
Collection[_MetadatumType]with an item-yielding__iter__; keyedaccess (
m[key],m.get(...)) is unchanged.Together these let
for key, value in err.trailing_metadata()type-check — itpreviously errored with "
_Metadatumis not iterable".Includes a regression test.
runtests.py --run-stubtest stubs/grpciopasses(mypy, pyright incl. stricter, test cases, stubtest).
Please let me know if I've overlooked something in the contribution process.