Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions stubs/grpcio/@tests/test_cases/check_aio.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@
async def metadata() -> None:
metadata = await cast(grpc.aio.Call, None).initial_metadata()
assert_type(metadata["foo"], grpc.aio._MetadataValue)
for k in metadata:
assert_type(k, str)

for k, v in metadata.items():
assert_type(k, str)
assert_type(v, grpc.aio._MetadataValue)
# grpc.aio.Metadata is a Collection that iterates as (key, value) tuples,
# not a Mapping that iterates bare keys.
for key, value in metadata:
assert_type(key, str)
assert_type(value, grpc.aio._MetadataValue)
20 changes: 17 additions & 3 deletions stubs/grpcio/grpc/aio/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
import abc
import asyncio
from _typeshed import Incomplete
from collections.abc import AsyncIterable, AsyncIterator, Awaitable, Callable, Generator, Iterable, Iterator, Mapping, Sequence
from collections.abc import (
AsyncIterable,
AsyncIterator,
Awaitable,
Callable,
Collection,
Generator,
Iterable,
Iterator,
Mapping,
Sequence,
)
from concurrent import futures
from types import TracebackType
from typing import Any, Generic, NoReturn, TypeAlias, TypeVar, overload, type_check_only
Expand Down Expand Up @@ -42,6 +53,9 @@ class AioRpcError(RpcError):
) -> None: ...
def debug_error_string(self) -> str: ...
def initial_metadata(self) -> Metadata: ...
# AioRpcError returns the async Metadata, overriding the synchronous
# grpc.RpcError.trailing_metadata() -> tuple[_Metadatum, ...].
def trailing_metadata(self) -> Metadata: ... # type: ignore[override]

# Create Client:

Expand Down Expand Up @@ -445,7 +459,7 @@ _MetadatumType: TypeAlias = tuple[_MetadataKey, _MetadataValue]
_MetadataType: TypeAlias = Metadata | Sequence[_MetadatumType]
_T = TypeVar("_T")

class Metadata(Mapping[_MetadataKey, _MetadataValue]):
class Metadata(Collection[_MetadatumType]):
def __init__(self, *args: tuple[_MetadataKey, _MetadataValue]) -> None: ...
@classmethod
def from_tuple(cls, raw_metadata: tuple[_MetadataKey, _MetadataValue]) -> Metadata: ...
Expand All @@ -455,7 +469,7 @@ class Metadata(Mapping[_MetadataKey, _MetadataValue]):
def __setitem__(self, key: _MetadataKey, value: _MetadataValue) -> None: ...
def __delitem__(self, key: _MetadataKey) -> None: ...
def delete_all(self, key: _MetadataKey) -> None: ...
def __iter__(self) -> Iterator[_MetadataKey]: ...
def __iter__(self) -> Iterator[_MetadatumType]: ...

@overload
def get(self, key: _MetadataKey, default: None = None) -> _MetadataValue | None: ...
Expand Down
Loading