Skip to content

Commit afd8038

Browse files
Python: Fix source typing for pyright 1.1.410
Pyright 1.1.410 tightened several checks. Apply the same source fixes as upstream PR microsoft#6275: - anthropic: import AsyncAnthropicBedrock from anthropic.lib.bedrock and AsyncAnthropicVertex from anthropic.lib.vertex (no longer re-exported from the anthropic top-level package -> reportPrivateImportUsage). - core _types.py: cast the transform-hook result to UpdateT (reportAssignmentType). - core _workflows/_events.py: annotate the @contextmanager helper as Generator[None] instead of Iterator[None] (reportDeprecated). - redis: build the combined filter expression with an explicit loop instead of reduce(and_, ...), which pyright could no longer fully type (drops the now unused functools.reduce / operator.and_ imports). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 9080701 commit afd8038

6 files changed

Lines changed: 15 additions & 9 deletions

File tree

python/packages/anthropic/agent_framework_anthropic/_bedrock_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from agent_framework._settings import SecretString, load_settings
1515
from agent_framework._telemetry import get_user_agent
1616
from agent_framework.observability import ChatTelemetryLayer
17-
from anthropic import AsyncAnthropicBedrock
17+
from anthropic.lib.bedrock import AsyncAnthropicBedrock
1818

1919
from ._chat_client import AnthropicOptionsT, RawAnthropicClient
2020

python/packages/anthropic/agent_framework_anthropic/_chat_client.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@
3131
from agent_framework._tools import SHELL_TOOL_KIND_VALUE
3232
from agent_framework._types import _get_data_bytes_as_str # type: ignore
3333
from agent_framework.observability import ChatTelemetryLayer
34-
from anthropic import AsyncAnthropic, AsyncAnthropicBedrock, AsyncAnthropicFoundry, AsyncAnthropicVertex
34+
from anthropic import AsyncAnthropic, AsyncAnthropicFoundry
35+
from anthropic.lib.bedrock import AsyncAnthropicBedrock
36+
from anthropic.lib.vertex import AsyncAnthropicVertex
3537
from anthropic.types.beta import (
3638
BetaContentBlock,
3739
BetaMessage,

python/packages/anthropic/agent_framework_anthropic/_vertex_client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
from agent_framework._settings import load_settings
1515
from agent_framework._telemetry import get_user_agent
1616
from agent_framework.observability import ChatTelemetryLayer
17-
from anthropic import NOT_GIVEN, AsyncAnthropicVertex
17+
from anthropic import NOT_GIVEN
18+
from anthropic.lib.vertex import AsyncAnthropicVertex
1819

1920
from ._chat_client import AnthropicOptionsT, RawAnthropicClient
2021

python/packages/core/agent_framework/_types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3136,7 +3136,7 @@ async def __anext__(self) -> UpdateT:
31363136
if isawaitable(hooked):
31373137
hooked = await hooked
31383138
if hooked is not None:
3139-
update = hooked
3139+
update = cast(UpdateT, hooked)
31403140
return update
31413141

31423142
async def _resolve_stream_with_pull_contexts(self) -> AsyncIterable[UpdateT]:

python/packages/core/agent_framework/_workflows/_events.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import sys
77
import traceback as _traceback
88
import warnings
9-
from collections.abc import Iterator
9+
from collections.abc import Generator
1010
from contextlib import contextmanager
1111
from contextvars import ContextVar
1212
from dataclasses import dataclass
@@ -46,7 +46,7 @@ def _current_event_origin() -> WorkflowEventSource:
4646

4747

4848
@contextmanager
49-
def _framework_event_origin() -> Iterator[None]: # pyright: ignore[reportUnusedFunction]
49+
def _framework_event_origin() -> Generator[None]: # pyright: ignore[reportUnusedFunction]
5050
"""Temporarily mark subsequently created events as originating from the framework (internal)."""
5151
token = _event_origin_context.set(WorkflowEventSource.FRAMEWORK)
5252
try:

python/packages/redis/agent_framework_redis/_context_provider.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
import json
1212
import sys
13-
from functools import reduce
14-
from operator import and_
1513
from typing import TYPE_CHECKING, Any, ClassVar, Literal
1614

1715
import numpy as np
@@ -191,7 +189,12 @@ def schema_dict(self) -> dict[str, Any]:
191189
def _build_filter_from_dict(self, filters: dict[str, str | None]) -> Any | None:
192190
"""Builds a combined filter expression from simple equality tags."""
193191
parts: list[FilterExpression] = [Tag(k) == v for k, v in filters.items() if v]
194-
return reduce(and_, parts) if parts else None
192+
if not parts:
193+
return None
194+
combined = parts[0]
195+
for part in parts[1:]:
196+
combined = combined & part
197+
return combined
195198

196199
def _build_schema_dict(
197200
self,

0 commit comments

Comments
 (0)