FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[grpcio] Fix AioRpcError.trailing_metadata and Metadata iteration by pboulos · Pull Request #15899 · python/typeshed · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) .pyi  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
11 changes: 5 additions & 6 deletions stubs/grpcio/@tests/test_cases/check_aio.py
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
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)
24 changes: 19 additions & 5 deletions stubs/grpcio/grpc/aio/__init__.pyi
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
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 _typeshed import Incomplete, MaybeNone
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 @@ -41,7 +52,10 @@ class AioRpcError(RpcError):
debug_error_string: str | None = None,
) -> None: ...
def debug_error_string(self) -> str: ...
def initial_metadata(self) -> Metadata: ...
def initial_metadata(self) -> Metadata | MaybeNone: ...
# AioRpcError returns the async Metadata, overriding the synchronous
# grpc.RpcError.trailing_metadata() -> tuple[_Metadatum, ...].
def trailing_metadata(self) -> Metadata | MaybeNone: ... # 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

Back | FazBrowse Home | New Git URL