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
@@ -329,11 +329,11 @@ class OllamaChatClient(
env_file_path=env_file_path,
)
self.model_id = ollama_settings["model_id"]
self.model_id = ollama_settings["model_id"] # type: ignore[assignment, reportTypedDictNotRequiredAccess]
# we can just pass in None for the host, the default is set by the Ollama package.
self.client = client or AsyncClient(host=ollama_settings.get("host"))
# Save Host URL for serialization with to_dict()
self.host = str(self.client._client.base_url) # pyright: ignore[reportUnknownMemberType,reportPrivateUsage,reportUnknownArgumentType]
self.host = str(self.client._client.base_url) # type: ignore[reportUnknownMemberType,reportPrivateUsage,reportUnknownArgumentType]
super().__init__(
middleware=middleware,
@@ -5,7 +5,7 @@ from __future__ import annotations
import logging
import sys
from collections.abc import Sequence
from typing import Any, ClassVar, Generic, TypedDict
from typing import Any, ClassVar, Generic, TypedDict, cast
from agent_framework import (
BaseEmbeddingClient,
@@ -107,9 +107,9 @@ class RawOllamaEmbeddingClient(
env_file_encoding=env_file_encoding,
)
self.model_id = ollama_settings["embedding_model_id"]
self.model_id = ollama_settings["embedding_model_id"] # type: ignore[assignment,reportTypedDictNotRequiredAccess]
self.client = client or AsyncClient(host=ollama_settings.get("host"))
self.host = str(self.client._client.base_url) # pyright: ignore[reportUnknownMemberType,reportPrivateUsage,reportUnknownArgumentType]
self.host = str(self.client._client.base_url) # type: ignore[reportUnknownMemberType,reportPrivateUsage,reportUnknownArgumentType]
super().__init__(**kwargs)
def service_url(self) -> str:
@@ -120,8 +120,8 @@ class RawOllamaEmbeddingClient(
self,
values: Sequence[str],
*,
options: OllamaEmbeddingOptionsT | None = None,
) -> GeneratedEmbeddings[list[float]]:
options: OllamaEmbeddingOptionsT | None = None, # type: ignore
) -> GeneratedEmbeddings[list[float], OllamaEmbeddingOptionsT]:
"""Call the Ollama embed API.
Args:
@@ -137,7 +137,7 @@ class RawOllamaEmbeddingClient(
if not values:
return GeneratedEmbeddings([], options=options)
opts: dict[str, Any] = dict(options) if options else {}
opts: dict[str, Any] = options or {} # type: ignore
model = opts.get("model_id") or self.model_id
if not model:
raise ValueError("model_id is required")
@@ -156,7 +156,7 @@ class RawOllamaEmbeddingClient(
Embedding(
vector=list(emb),
dimensions=len(emb),
model_id=response.get("model") or model,
model_id=response.get("model") or model, # type: ignore[assignment]
)
for emb in response.get("embeddings", [])
]
@@ -166,7 +166,7 @@ class RawOllamaEmbeddingClient(
if prompt_eval_count is not None:
usage_dict = {"input_token_count": prompt_eval_count}
return GeneratedEmbeddings(embeddings, options=options, usage=usage_dict)
return GeneratedEmbeddings(embeddings, options=cast(OllamaEmbeddingOptionsT, opts), usage=usage_dict)
class OllamaEmbeddingClient(
+2 -1
View File
@@ -62,6 +62,7 @@ omit = [
[tool.pyright]
extends = "../../pyproject.toml"
include = ["agent_framework_ollama"]
exclude = ['tests']
[tool.mypy]
@@ -89,7 +90,7 @@ include = "../../shared_tasks.toml"
[tool.poe.tasks]
mypy = "mypy --config-file $POE_ROOT/pyproject.toml agent_framework_ollama"
test = "pytest --cov=agent_framework_ollama --cov-report=term-missing:skip-covered tests"
test = "pytest -m \"not integration\" --cov=agent_framework_ollama --cov-report=term-missing:skip-covered tests"
[tool.uv.build-backend]
module-name = "agent_framework_ollama"