Skip to content

Commit c9ee9e4

Browse files
committed
refactor: Add TYPE_CHECKING import for MetadataType and type hint context.invocation_metadata() return
1 parent 56c99e3 commit c9ee9e4

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

src/a2a/server/request_handlers/grpc_handler.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@
44

55
from abc import ABC, abstractmethod
66
from collections.abc import AsyncIterable, Awaitable, Sequence
7+
from typing import TYPE_CHECKING
78

89

910
try:
1011
import grpc
1112
import grpc.aio
1213

14+
if TYPE_CHECKING:
15+
from grpc.aio._typing import MetadataType
1316
from grpc.aio import Metadata
1417
except ImportError as e:
1518
raise ImportError(
@@ -53,7 +56,7 @@ def build(self, context: grpc.aio.ServicerContext) -> ServerCallContext:
5356
def _get_metadata_value(
5457
context: grpc.aio.ServicerContext, key: str
5558
) -> list[str]:
56-
md = context.invocation_metadata()
59+
md: MetadataType | None = context.invocation_metadata()
5760
raw_values: list[str | bytes] = []
5861
lower_key = key.lower()
5962
if isinstance(md, Metadata):

0 commit comments

Comments
 (0)