Skip to content

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

Open
eavanvalkenburg wants to merge 5 commits intomicrosoft:mainfrom
eavanvalkenburg:fix/issue-4407-pyright-remediation
Open

Python: Fix Python pyright package scoping and typing remediation#4426
eavanvalkenburg wants to merge 5 commits intomicrosoft:mainfrom
eavanvalkenburg:fix/issue-4407-pyright-remediation

Conversation

@eavanvalkenburg
Copy link
Member

@eavanvalkenburg eavanvalkenburg commented Mar 3, 2026

Summary

  • remove root pyright include and move include scoping to package-level pyproject configs
  • resolve pyright and mypy typing issues across Python packages for the new scope
  • simplify redundant casts and defensive setting checks where required_fields already validate

Copilot AI review requested due to automatic review settings March 3, 2026 16:46
@eavanvalkenburg eavanvalkenburg requested a review from a team as a code owner March 3, 2026 16:46
@markwallace-microsoft markwallace-microsoft added documentation Improvements or additions to documentation python lab Agent Framework Lab labels Mar 3, 2026
@github-actions github-actions bot changed the title Fix Python pyright package scoping and typing remediation Python: Fix Python pyright package scoping and typing remediation Mar 3, 2026
@eavanvalkenburg eavanvalkenburg force-pushed the fix/issue-4407-pyright-remediation branch from d298834 to 308326e Compare March 3, 2026 16:49
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adjusts Python type-checking scope to be package-local (pyright include moved to each package) and remediates the resulting pyright/mypy issues across the Python packages by tightening types, adding targeted helpers, and reducing unsafe casts.

Changes:

  • Remove the root pyright include and add per-package tool.pyright.include entries in each package pyproject.toml.
  • Remediate typing issues across multiple packages (more precise types, safer dict/list coercions, overloads/TypeGuards, targeted pyright: ignore[...]).
  • Minor API/utility refinements to support the new typing constraints (e.g., typed request/session records, safer error payload extraction, small helper functions).

Reviewed changes

Copilot reviewed 100 out of 100 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
python/pyproject.toml Removes root-level pyright include to allow package-level scoping.
python/packages/redis/pyproject.toml Adds pyright include for redis package.
python/packages/redis/agent_framework_redis/_history_provider.py Adds explicit typing for lrange results to satisfy type checking.
python/packages/redis/agent_framework_redis/_context_provider.py Reduces casts, adds targeted pyright ignores, and tightens filter/search typing.
python/packages/purview/pyproject.toml Adds pyright include for purview package.
python/packages/purview/agent_framework_purview/_processor.py Avoids required-setting indexing; normalizes app name and cache TTL handling.
python/packages/purview/agent_framework_purview/_models.py Adds safe coercion helpers and removes redundant casts in model normalization/deserialization.
python/packages/purview/agent_framework_purview/_middleware.py Improves local variable typing and session-id handling for policy checks.
python/packages/purview/agent_framework_purview/_client.py Adds overloads/TypeVar for _post and improves response typing/deserialization.
python/packages/orchestrations/pyproject.toml Adds pyright include for orchestrations package.
python/packages/orchestrations/agent_framework_orchestrations/_handoff.py Improves typing around chat agent cloning/options and handoff handling.
python/packages/ollama/pyproject.toml Adds pyright include for ollama package.
python/packages/ollama/agent_framework_ollama/_embedding_client.py Tightens options typing and normalizes returned options in GeneratedEmbeddings.
python/packages/ollama/agent_framework_ollama/_chat_client.py Adds typed-dict access ignore for required model id.
python/packages/mem0/pyproject.toml Adds pyright include for mem0 package.
python/packages/mem0/agent_framework_mem0/_context_provider.py Adds targeted pyright ignore for context-manager exit typing.
python/packages/lab/tau2/agent_framework_lab_tau2/runner.py Adds a typed helper to safely obtain openai_schema.
python/packages/lab/tau2/agent_framework_lab_tau2/_tau2_utils.py Adds TypeGuards/coercions for safer message/tool conversions and JSON handling.
python/packages/lab/tau2/agent_framework_lab_tau2/_message_utils.py Adds explicit list typing for transformed messages.
python/packages/lab/pyproject.toml Adds package-level pyright include paths for lab subpackages.
python/packages/lab/gaia/agent_framework_lab_gaia/gaia.py Adds coercion helpers and hardens parsing/IO typing for dataset loading/scoring.
python/packages/github_copilot/pyproject.toml Adds pyright include for GitHub Copilot package.
python/packages/github_copilot/agent_framework_github_copilot/_agent.py Avoids required-setting indexing and uses typed MessageOptions payloads.
python/packages/foundry_local/pyproject.toml Adds pyright include for foundry_local package.
python/packages/foundry_local/agent_framework_foundry_local/_foundry_local_client.py Avoids repeated TypedDict indexing; uses a single resolved model_id variable.
python/packages/durabletask/pyproject.toml Adds pyright include for durabletask package.
python/packages/durabletask/agent_framework_durabletask/_response_utils.py Adds targeted pyright ignores for private response fields.
python/packages/durabletask/agent_framework_durabletask/_entities.py Simplifies run() method access (assumes agent implements run).
python/packages/devui/agent_framework_devui/models/_discovery_models.py Uses a named default_factory helper to satisfy typing/linting constraints.
python/packages/devui/agent_framework_devui/_utils.py Adds helper to safely coerce dicts into string-key dicts and tightens schema parsing logic.
python/packages/devui/agent_framework_devui/_session.py Introduces TypedDicts for session/request records and aligns stored model field naming.
python/packages/devui/agent_framework_devui/_server.py Adds typed OpenAI error extraction helper and hardens JSON/dict serialization paths.
python/packages/devui/agent_framework_devui/_openai/_executor.py Adds typed OpenAI error extraction helper and uses it for structured error events.
python/packages/devui/agent_framework_devui/_mapper.py Improves dict/list serialization safety and streamlines event conversion typing.
python/packages/devui/agent_framework_devui/_executor.py Removes reliance on private request methods and hardens parsing/typing of OpenAI-style inputs.
python/packages/devui/agent_framework_devui/_discovery.py Renames cleanup hook accessor and tightens tool extraction typing.
python/packages/devui/agent_framework_devui/_deployment.py Hardens JSON parsing and URL host handling types.
python/packages/devui/agent_framework_devui/_conversations.py Tightens typing of content/message conversion for conversation storage operations.
python/packages/devui/agent_framework_devui/init.py Publicly exposes cleanup hook accessor, keeps backward-compatible alias, uses setter for pending entities.
python/packages/declarative/agent_framework_declarative/_workflows/_state.py Adds explicit casts for list/dict handling to satisfy type checkers.
python/packages/declarative/agent_framework_declarative/_workflows/_powerfx_functions.py Tightens list/dict handling and attribute access typing.
python/packages/declarative/agent_framework_declarative/_workflows/_executors_tools.py Adds typed defaults, Mapping checks, and safer argument iteration.
python/packages/declarative/agent_framework_declarative/_workflows/_executors_basic.py Uses Mapping-based parsing and safer assignment typing for declarative executors.
python/packages/declarative/agent_framework_declarative/_workflows/_executors_agents.py Simplifies content presence check for message history validation.
python/packages/declarative/agent_framework_declarative/_workflows/_declarative_builder.py Hardens action-def access typing when checking terminators.
python/packages/declarative/agent_framework_declarative/_workflows/_declarative_base.py Improves PowerFx-safe coercion typing and adds targeted pyright ignores for interop imports.
python/packages/declarative/agent_framework_declarative/_loader.py Adds private-usage ignore and handles ReferenceConnection explicitly.
python/packages/core/pyproject.toml Disables mypy incremental mode for core package.
python/packages/core/agent_framework/openai/_shared.py Uses Mapping typing for tool dict handling.
python/packages/core/agent_framework/openai/_responses_client.py Avoids required TypedDict indexing; resolves required settings via .get().
python/packages/core/agent_framework/openai/_embedding_client.py Adds explicit casts for GeneratedEmbeddings generics.
python/packages/core/agent_framework/openai/_chat_client.py Improves tool pass-through handling and safer content flattening logic.
python/packages/core/agent_framework/openai/_assistants_client.py Avoids required TypedDict indexing and annotates deprecated beta calls.
python/packages/core/agent_framework/openai/_assistant_provider.py Avoids required TypedDict indexing and tightens tool validation typing.
python/packages/core/agent_framework/observability.py Avoids rebinding the global settings instance; improves typing around super() callables and streams.
python/packages/core/agent_framework/declarative/init.pyi Removes an exported symbol from the stub to match current surface.
python/packages/core/agent_framework/azure/_shared.py Adds an alias for the defaults applier (likely for typing/import stability).
python/packages/core/agent_framework/azure/_responses_client.py Avoids required TypedDict indexing and improves endpoint/base_url handling.
python/packages/core/agent_framework/azure/_embedding_client.py Avoids required TypedDict indexing and improves deployment/api-version handling.
python/packages/core/agent_framework/azure/_chat_client.py Avoids required TypedDict indexing and hardens context/citations typing.
python/packages/core/agent_framework/azure/_assistants_client.py Avoids required TypedDict indexing and improves azure client creation typing.
python/packages/core/agent_framework/_workflows/_typing_utils.py Ensures coercion fallbacks return the original value and improves pydantic/dataclass coercion typing.
python/packages/core/agent_framework/_workflows/_function_executor.py Uses inspect.iscoroutinefunction for async detection.
python/packages/core/agent_framework/_workflows/_agent_executor.py Removes redundant key-type checks after Mapping casts.
python/packages/core/agent_framework/_skills.py Adjusts default_factory to satisfy typing constraints.
python/packages/core/agent_framework/_settings.py Simplifies dotenv filtering logic used by settings loader.
python/packages/core/agent_framework/_sessions.py Improves dict key normalization and tool metadata injection typing.
python/packages/core/agent_framework/_serialization.py Hardens list/dict serialization by stringifying keys and adding targeted ignores.
python/packages/core/agent_framework/_middleware.py Normalizes metadata/kwargs as real dicts and tightens middleware pipeline typing.
python/packages/core/agent_framework/_clients.py Tightens ChatResponse generic return type annotation.
python/packages/core/agent_framework/_agents.py Improves dict tool name extraction and callability checks.
python/packages/copilotstudio/pyproject.toml Adds pyright include for copilotstudio package.
python/packages/copilotstudio/agent_framework_copilotstudio/_agent.py Avoids required TypedDict indexing by pre-resolving required settings.
python/packages/claude/pyproject.toml Adds pyright include for claude package.
python/packages/claude/agent_framework_claude/_agent.py Improves tool normalization logic and typing around builtin vs custom tools.
python/packages/chatkit/pyproject.toml Adds pyright include for chatkit package.
python/packages/bedrock/pyproject.toml Adds pyright include for bedrock package.
python/packages/bedrock/agent_framework_bedrock/_embedding_client.py Adds Protocols for runtime client/response and hardens response parsing/typing.
python/packages/bedrock/agent_framework_bedrock/_chat_client.py Adds Protocol/TypeGuards and safer Bedrock response parsing.
python/packages/azurefunctions/pyproject.toml Adds pyright include for azurefunctions package.
python/packages/azurefunctions/agent_framework_azurefunctions/_workflow.py Hardens typing around DF orchestration calls and HITL response handling.
python/packages/azurefunctions/agent_framework_azurefunctions/_serialization.py Renames type resolver to public name and hardens pydantic validation invocation.
python/packages/azurefunctions/agent_framework_azurefunctions/_context.py Adjusts captured message typing in runner context.
python/packages/azurefunctions/agent_framework_azurefunctions/_app.py Adds stronger runtime validation/coercion for activity input payloads.
python/packages/azure-cosmos/pyproject.toml Adds pyright include for azure-cosmos package.
python/packages/azure-cosmos/agent_framework_azure_cosmos/_history_provider.py Adds TypeGuard for message payload dict typing.
python/packages/azure-ai/pyproject.toml Adds pyright include for azure-ai package.
python/packages/azure-ai/agent_framework_azure_ai/_shared.py Tightens mapping handling for tool resources and MCP tool configuration extraction.
python/packages/azure-ai/agent_framework_azure_ai/_project_provider.py Tightens typing for non-MCP tool collection.
python/packages/azure-ai/agent_framework_azure_ai/_client.py Adds safer imports for Azure Monitor, improves tool name extraction, and normalizes chat roles.
python/packages/azure-ai/agent_framework_azure_ai/_chat_client.py Hardens tool-call parsing and tool resource updates with Mapping checks.
python/packages/azure-ai-search/pyproject.toml Adds pyright include for azure-ai-search package.
python/packages/azure-ai-search/agent_framework_azure_ai_search/_context_provider.py Normalizes embedding vectors to list[float] and adds a default match case.
python/packages/anthropic/agent_framework_anthropic/_chat_client.py Avoids required TypedDict indexing and improves MCP tool parsing with Mapping checks.
python/packages/ag-ui/pyproject.toml Adds pyright include for ag-ui package.
python/packages/a2a/pyproject.toml Adds pyright include for a2a package.
python/packages/a2a/agent_framework_a2a/_agent.py Adds TypeAliases for stream items and tightens content validation for required fields.
python/CODING_STANDARD.md Documents a pyright ignore/cast policy for the repo.

@eavanvalkenburg eavanvalkenburg force-pushed the fix/issue-4407-pyright-remediation branch from 03a6694 to 1c80c86 Compare March 3, 2026 19:29
eavanvalkenburg and others added 5 commits March 4, 2026 09:35
Implements issue microsoft#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>
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>
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>
@eavanvalkenburg eavanvalkenburg force-pushed the fix/issue-4407-pyright-remediation branch from 15d546b to 8d69b7a Compare March 4, 2026 08:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation lab Agent Framework Lab python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants