Python: Fix Python pyright package scoping and typing remediation (#4426)

* Fix Python pyright package scoping and typing remediation

Implements issue #4407 by removing the root pyright include, adding package-level pyright includes, and resolving pyright/mypy typing issues across Python packages. Also cleans unnecessary casts and applies line-level, rule-specific ignores where external libraries are too dynamic.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Reduce pyright cost in handoff cloning

Simplify cloned_options construction in HandoffAgentExecutor to avoid expensive TypedDict narrowing/inference in _handoff.py, which was causing pyright to spend a long time in orchestrations.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* fix types

* Fix lint and type-check regressions

Resolve current Python package check failures across lint, pyright, and mypy after recent code changes, including purview/declarative pyright issues and multiple ruff simplification findings.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* fixed hooks

* Stabilize package tests and test tasks

Resolve cross-package non-integration test failures, simplify streaming type flow, harden locale/culture handling, and standardize package test poe tasks to exclude integration tests where applicable.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* lots of small fixes

* Fix current Python test regressions

Address current failing unit tests in azure-ai, bedrock, and azure-cosmos while keeping Bedrock parsing logic inline (no new static helper methods).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* small fixes

* small fixes

* removed pydantic from json

* final updates

* fix core

* fix tests

* fix obser

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Eduard van Valkenburg
2026-03-05 16:32:24 +01:00
committed by GitHub
Unverified
parent 4a043c6c66
commit 55ddd841b7
122 changed files with 2328 additions and 2407 deletions
@@ -7,7 +7,7 @@ import json
import re
import uuid
from collections.abc import AsyncIterable, Awaitable, Sequence
from typing import Any, Final, Literal, overload
from typing import Any, Final, Literal, TypeAlias, overload
import httpx
from a2a.client import Client, ClientConfig, ClientFactory, minimal_agent_card
@@ -19,9 +19,11 @@ from a2a.types import (
FileWithBytes,
FileWithUri,
Task,
TaskArtifactUpdateEvent,
TaskIdParams,
TaskQueryParams,
TaskState,
TaskStatusUpdateEvent,
TextPart,
TransportProtocol,
)
@@ -70,6 +72,9 @@ IN_PROGRESS_TASK_STATES = [
TaskState.auth_required,
]
A2AClientEvent: TypeAlias = tuple[Task, TaskStatusUpdateEvent | TaskArtifactUpdateEvent | None]
A2AStreamItem: TypeAlias = A2AMessage | A2AClientEvent
def _get_uri_data(uri: str) -> str:
match = URI_PATTERN.match(uri)
@@ -260,7 +265,9 @@ class A2AAgent(AgentTelemetryLayer, BaseAgent):
When stream=True: A ResponseStream of AgentResponseUpdate items.
"""
if continuation_token is not None:
a2a_stream: AsyncIterable[Any] = self.client.resubscribe(TaskIdParams(id=continuation_token["task_id"]))
a2a_stream: AsyncIterable[A2AStreamItem] = self.client.resubscribe(
TaskIdParams(id=continuation_token["task_id"])
)
else:
normalized_messages = normalize_messages(messages)
a2a_message = self._prepare_message_for_a2a(normalized_messages[-1])
@@ -276,7 +283,7 @@ class A2AAgent(AgentTelemetryLayer, BaseAgent):
async def _map_a2a_stream(
self,
a2a_stream: AsyncIterable[Any],
a2a_stream: AsyncIterable[A2AStreamItem],
*,
background: bool = False,
) -> AsyncIterable[AgentResponseUpdate]:
@@ -300,14 +307,12 @@ class A2AAgent(AgentTelemetryLayer, BaseAgent):
response_id=str(getattr(item, "message_id", uuid.uuid4())),
raw_representation=item,
)
elif isinstance(item, tuple) and len(item) == 2: # ClientEvent = (Task, UpdateEvent)
elif isinstance(item, tuple) and len(item) == 2 and isinstance(item[0], Task):
task, _update_event = item
if isinstance(task, Task):
for update in self._updates_from_task(task, background=background):
yield update
for update in self._updates_from_task(task, background=background):
yield update
else:
msg = f"Only Message and Task responses are supported from A2A agents. Received: {type(item)}"
raise NotImplementedError(msg)
raise NotImplementedError("Only Message and Task responses are supported")
# ------------------------------------------------------------------
# Task helpers
@@ -396,6 +401,8 @@ class A2AAgent(AgentTelemetryLayer, BaseAgent):
for content in message.contents:
match content.type:
case "text":
if content.text is None:
raise ValueError("Text content requires a non-null text value")
parts.append(
A2APart(
root=TextPart(
@@ -414,6 +421,8 @@ class A2AAgent(AgentTelemetryLayer, BaseAgent):
)
)
case "uri":
if content.uri is None:
raise ValueError("URI content requires a non-null uri value")
parts.append(
A2APart(
root=FilePart(
@@ -426,11 +435,13 @@ class A2AAgent(AgentTelemetryLayer, BaseAgent):
)
)
case "data":
if content.uri is None:
raise ValueError("Data content requires a non-null uri value")
parts.append(
A2APart(
root=FilePart(
file=FileWithBytes(
bytes=_get_uri_data(content.uri), # type: ignore[arg-type]
bytes=_get_uri_data(content.uri),
mime_type=content.media_type,
),
metadata=content.additional_properties,
@@ -438,6 +449,8 @@ class A2AAgent(AgentTelemetryLayer, BaseAgent):
)
)
case "hosted_file":
if content.file_id is None:
raise ValueError("Hosted file content requires a non-null file_id value")
parts.append(
A2APart(
root=FilePart(
+2 -1
View File
@@ -61,6 +61,7 @@ omit = [
[tool.pyright]
extends = "../../pyproject.toml"
include = ["agent_framework_a2a"]
[tool.mypy]
plugins = ['pydantic.mypy']
@@ -86,7 +87,7 @@ include = "../../shared_tasks.toml"
[tool.poe.tasks]
mypy = "mypy --config-file $POE_ROOT/pyproject.toml agent_framework_a2a"
test = "pytest --cov=agent_framework_a2a --cov-report=term-missing:skip-covered tests"
test = "pytest -m \"not integration\" --cov=agent_framework_a2a --cov-report=term-missing:skip-covered tests"
[build-system]
requires = ["flit-core >= 3.11,<4.0"]