mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
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:
committed by
GitHub
Unverified
parent
4a043c6c66
commit
55ddd841b7
@@ -560,8 +560,6 @@ instructions: You are a helpful assistant.
|
||||
"""Test that outputSchema is passed as response_format in Agent.default_options."""
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from agent_framework_declarative import AgentFactory
|
||||
|
||||
agent_def = {
|
||||
@@ -580,8 +578,10 @@ instructions: You are a helpful assistant.
|
||||
agent = factory.create_agent_from_dict(agent_def)
|
||||
|
||||
assert "response_format" in agent.default_options
|
||||
assert isinstance(agent.default_options["response_format"], type)
|
||||
assert issubclass(agent.default_options["response_format"], BaseModel)
|
||||
response_format = agent.default_options["response_format"]
|
||||
assert isinstance(response_format, dict)
|
||||
assert response_format["type"] == "object"
|
||||
assert response_format["properties"]["answer"]["type"] == "string"
|
||||
|
||||
def test_create_agent_from_dict_chat_options_in_default_options(self):
|
||||
"""Test that chat options (temperature, top_p) are in Agent.default_options."""
|
||||
|
||||
@@ -16,6 +16,7 @@ Coverage includes:
|
||||
- String interpolation: {Variable.Path}
|
||||
"""
|
||||
|
||||
import locale
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
import pytest
|
||||
@@ -494,29 +495,38 @@ class TestPowerFxUndefinedVariables:
|
||||
assert result is None
|
||||
|
||||
async def test_undefined_variable_returns_none_with_non_english_ui_culture(self, mock_state):
|
||||
"""Test that undefined variables return None even when CurrentUICulture is non-English.
|
||||
"""Test that undefined variables return None even when locale is non-English.
|
||||
|
||||
Regression test for #4321: on non-English systems, CurrentUICulture causes
|
||||
Regression test for #4321: on non-English systems, locale settings can cause
|
||||
PowerFx to emit localized error messages that don't match the English
|
||||
string guards ("isn't recognized", "Name isn't valid"), crashing the workflow.
|
||||
The fix sets CurrentUICulture to en-US alongside CurrentCulture before eval.
|
||||
The fix evaluates with locale='en-US' and restores the ambient LC_NUMERIC.
|
||||
"""
|
||||
from System.Globalization import CultureInfo
|
||||
|
||||
state = DeclarativeWorkflowState(mock_state)
|
||||
state.initialize()
|
||||
|
||||
# Simulate a non-English UI culture (e.g. Italian)
|
||||
original_ui_culture = CultureInfo.CurrentUICulture
|
||||
CultureInfo.CurrentUICulture = CultureInfo("it-IT")
|
||||
# Simulate a non-English locale (e.g. Italian)
|
||||
original_numeric_locale = locale.setlocale(locale.LC_NUMERIC)
|
||||
test_numeric_locale: str | None = None
|
||||
try:
|
||||
for locale_candidate in ("it_IT.UTF-8", "it_IT", "fr_FR.UTF-8", "fr_FR", "de_DE.UTF-8", "de_DE"):
|
||||
try:
|
||||
locale.setlocale(locale.LC_NUMERIC, locale_candidate)
|
||||
test_numeric_locale = locale.setlocale(locale.LC_NUMERIC)
|
||||
break
|
||||
except locale.Error:
|
||||
continue
|
||||
|
||||
if test_numeric_locale is None:
|
||||
pytest.skip("No non-English LC_NUMERIC locale available on this system")
|
||||
|
||||
# Should return None, not raise ValueError with Italian error text
|
||||
result = state.eval("=Local.StatusConversationId")
|
||||
assert result is None
|
||||
# Verify the production code restored CurrentUICulture after eval
|
||||
assert str(CultureInfo.CurrentUICulture) == str(CultureInfo("it-IT"))
|
||||
# Verify the production code restored LC_NUMERIC after eval
|
||||
assert locale.setlocale(locale.LC_NUMERIC) == test_numeric_locale
|
||||
finally:
|
||||
CultureInfo.CurrentUICulture = original_ui_culture
|
||||
locale.setlocale(locale.LC_NUMERIC, original_numeric_locale)
|
||||
|
||||
|
||||
class TestStringInterpolation:
|
||||
|
||||
Reference in New Issue
Block a user